Skip to content
This repository has been archived by the owner on May 6, 2024. It is now read-only.

refactor: Replace listView with recyclerView for Discussion Screen #1821

Merged
merged 5 commits into from
Sep 19, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 19 additions & 22 deletions OpenEdXMobile/res/layout/fragment_discussion_search_posts.xml
Original file line number Diff line number Diff line change
@@ -1,27 +1,24 @@
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">

<LinearLayout
<SearchView
android:id="@+id/discussion_topics_searchview"
style="@style/discussion_topics_search_bar"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">

<SearchView
android:id="@+id/discussion_topics_searchview"
style="@style/discussion_topics_search_bar"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
android:layout_height="wrap_content" />

<View style="@style/gray_separator" />
<View style="@style/gray_separator" />

<ListView
android:id="@+id/discussion_posts_listview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/white"
android:visibility="invisible"
tools:listitem="@layout/row_discussion_thread"
tools:visibility="visible" />
</LinearLayout>
</layout>
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/discussion_posts_rv"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/white"
android:visibility="invisible"
tools:listitem="@layout/row_discussion_thread"
tools:visibility="visible" />
HamzaIsrar12 marked this conversation as resolved.
Show resolved Hide resolved
</LinearLayout>
133 changes: 66 additions & 67 deletions OpenEdXMobile/res/layout/fragment_discussion_thread_posts.xml
Original file line number Diff line number Diff line change
@@ -1,85 +1,84 @@
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/content_error_root"
android:layout_width="match_parent"
android:layout_height="match_parent">

<FrameLayout
android:id="@+id/content_error_root"
<LinearLayout
android:id="@+id/content"
android:layout_width="match_parent"
android:layout_height="match_parent">
android:layout_height="match_parent"
android:orientation="vertical">

<LinearLayout
android:id="@+id/content"
android:id="@+id/spinners_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
android:layout_height="@dimen/discussion_post_refine_layout_height"
android:background="@color/white"
android:orientation="horizontal"
android:visibility="gone"
tools:visibility="visible">

<LinearLayout
android:id="@+id/spinners_container"
android:layout_width="match_parent"
android:layout_height="@dimen/discussion_post_refine_layout_height"
android:background="@color/white"
android:orientation="horizontal"
android:visibility="gone"
tools:visibility="visible">
<TextView
android:id="@+id/discussion_posts_refine_text_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginStart="@dimen/edx_margin"
android:text="@string/discussion_posts_refine"
android:textColor="@color/primaryXLightColor" />

<TextView
android:id="@+id/discussion_posts_refine_text_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginStart="@dimen/edx_margin"
android:text="@string/discussion_posts_refine"
android:textColor="@color/primaryXLightColor" />

<androidx.appcompat.widget.AppCompatSpinner
android:id="@+id/discussion_posts_filter_spinner"
style="?attr/popupSpinnerStyle"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_marginStart="@dimen/edx_margin"
android:layout_weight="1"
tools:listitem="@layout/row_discussion_thread_dropdown" />

<androidx.appcompat.widget.AppCompatSpinner
android:id="@+id/discussion_posts_sort_spinner"
style="?attr/popupSpinnerStyle"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
tools:listitem="@layout/row_discussion_thread_dropdown" />

</LinearLayout>

<Space style="@style/gray_separator" />

<ListView
android:id="@+id/discussion_posts_listview"
android:layout_width="match_parent"
android:layout_height="0dp"
<androidx.appcompat.widget.AppCompatSpinner
android:id="@+id/discussion_posts_filter_spinner"
style="?attr/popupSpinnerStyle"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_marginStart="@dimen/edx_margin"
android:layout_weight="1"
android:background="@color/white"
android:visibility="invisible"
tools:listitem="@layout/row_discussion_thread"
tools:visibility="visible" />
tools:listitem="@layout/row_discussion_thread_dropdown" />

<include
android:id="@+id/create_new_item"
layout="@layout/create_new_item_layout" />
<androidx.appcompat.widget.AppCompatSpinner
android:id="@+id/discussion_posts_sort_spinner"
style="?attr/popupSpinnerStyle"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
tools:listitem="@layout/row_discussion_thread_dropdown" />

</LinearLayout>

<TextView
android:id="@+id/center_message_box"
style="@style/content_unavailable_error_text"
tools:text="Error text comes here."
<Space style="@style/gray_separator" />

<androidx.recyclerview.widget.RecyclerView
android:id="@+id/discussion_posts_rv"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:background="@color/white"
android:visibility="invisible"
tools:listitem="@layout/row_discussion_thread"
HamzaIsrar12 marked this conversation as resolved.
Show resolved Hide resolved
tools:visibility="visible" />

<include
android:id="@+id/loading_indicator"
layout="@layout/loading_indicator"
tools:visibility="visible" />
android:id="@+id/create_new_item"
layout="@layout/create_new_item_layout" />

</LinearLayout>

<TextView
android:id="@+id/center_message_box"
style="@style/content_unavailable_error_text"
tools:text="Error text comes here."
tools:visibility="visible" />

<include
android:id="@+id/loading_indicator"
layout="@layout/loading_indicator"
tools:visibility="visible" />

<include layout="@layout/content_error" />
<include
layout="@layout/content_error"
tools:visibility="gone" />

</FrameLayout>
</layout>
</FrameLayout>
64 changes: 32 additions & 32 deletions OpenEdXMobile/res/layout/fragment_discussion_topics.xml
Original file line number Diff line number Diff line change
@@ -1,41 +1,41 @@
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">

<FrameLayout
android:id="@+id/content_error_root"
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/content_error_root"
android:layout_width="match_parent"
android:layout_height="match_parent">

<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
android:layout_height="match_parent"
android:background="@color/white"
android:orientation="vertical">

<LinearLayout
<SearchView
android:id="@+id/discussion_topics_searchview"
style="@style/discussion_topics_search_bar"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/white"
android:orientation="vertical">

<SearchView
android:id="@+id/discussion_topics_searchview"
style="@style/discussion_topics_search_bar"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
android:layout_height="wrap_content" />

<View style="@style/gray_separator" />
<View style="@style/gray_separator" />

<ListView
android:id="@+id/discussion_topics_listview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/white"
android:nestedScrollingEnabled="true"
tools:listitem="@layout/row_discussion_topic" />

</LinearLayout>
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/discussion_topics_rv"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/white"
android:nestedScrollingEnabled="true"
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
tools:listitem="@layout/row_discussion_topic" />

<include
android:id="@+id/loading_indicator"
layout="@layout/loading_indicator" />
</LinearLayout>

<include layout="@layout/content_error" />
<include
android:id="@+id/loading_indicator"
layout="@layout/loading_indicator" />

</FrameLayout>
</layout>
<include
layout="@layout/content_error"
android:visibility="gone" />
HamzaIsrar12 marked this conversation as resolved.
Show resolved Hide resolved
</FrameLayout>
1 change: 1 addition & 0 deletions OpenEdXMobile/res/layout/row_discussion_thread.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/view_selector"
android:orientation="horizontal"
android:paddingTop="@dimen/edx_margin"
android:paddingBottom="@dimen/edx_margin">
Expand Down
1 change: 1 addition & 0 deletions OpenEdXMobile/res/layout/row_discussion_topic.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@
android:singleLine="true"
android:textDirection="locale"
android:textSize="@dimen/edx_base"
android:background="@drawable/view_selector"
HamzaIsrar12 marked this conversation as resolved.
Show resolved Hide resolved
tools:text="Topic Name" />
1 change: 1 addition & 0 deletions OpenEdXMobile/res/values/styles.xml
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,7 @@
<style name="discussion_topics_search_bar" parent="search_bar">
<item name="android:queryHint">@string/topics_search</item>
<item name="android:background">@color/white</item>
<item name="android:queryBackground">@android:color/transparent</item>
<item name="android:iconifiedByDefault">false</item>
</style>

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package org.edx.mobile.extenstion
HamzaIsrar12 marked this conversation as resolved.
Show resolved Hide resolved

import androidx.appcompat.widget.AppCompatImageView
import org.edx.mobile.util.UiUtils

fun AppCompatImageView.setSrcColor(colorRes: Int) {
UiUtils.setImageViewColor(this.context, this, colorRes)
HamzaIsrar12 marked this conversation as resolved.
Show resolved Hide resolved
}
omerhabib26 marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.edx.mobile.extenstion

import android.graphics.drawable.Drawable
import android.os.Build
import android.text.Editable
import android.text.Spannable
import android.text.SpannableString
Expand All @@ -11,6 +12,7 @@ import android.text.style.ImageSpan
import android.text.style.URLSpan
import android.text.util.Linkify
import android.widget.TextView
import androidx.annotation.StyleRes
import androidx.core.text.HtmlCompat

fun TextView.addAfterTextChanged(listener: (Editable) -> Unit) {
Expand Down Expand Up @@ -86,3 +88,13 @@ fun TextView.setTextWithIcon(fullText: String, drawable: Drawable, targetText: S
}
this.text = spannableString
}

fun TextView.setCustomTextAppearance(@StyleRes resId: Int) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
// Use the new method available in Android 12 and later
this.setTextAppearance(resId);
} else {
// Fallback for earlier Android versions
this.setTextAppearance(this.context, resId);
}
}
HamzaIsrar12 marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -190,4 +190,25 @@ class DiscussionThread : Serializable, IAuthorData, ProfileImageProvider {
newObj.users = users
return newObj
}

/**
* Checks whether an icon is visible in the action layout.
* Based on the result of this function we decide if we need to append
* a pipe sign before the following text to the icons.
*
* @return `true` if a thread is closed, pinned or being followed by a user,
* `false` otherwise.
HamzaIsrar12 marked this conversation as resolved.
Show resolved Hide resolved
*/
fun isAnyIconVisible(): Boolean {
return isClosed || isFollowing || isPinned
}
}

/**
* Format a number according to the count format.
* Based on the count value this function decides what string has to be
* shown to the user.
* @return 99+ if the count is equal to or greater than 99, otherwise the actual count
* as a String.
*/
fun Int.FormatedCount(): String = if (this >= 99) "99+" else this.toString()
HamzaIsrar12 marked this conversation as resolved.
Show resolved Hide resolved
Loading