mirror of
https://github.com/samuelclay/NewsBlur.git
synced 2025-09-18 21:50:56 +00:00
#1811 Verify error handling and show loading indicator to the user when adding a feed.
This commit is contained in:
parent
1ab88e4cc3
commit
c0d26b46ac
3 changed files with 33 additions and 19 deletions
|
@ -24,10 +24,9 @@ import com.newsblur.fragment.AddFeedFragment.AddFeedAdapter.FolderViewHolder
|
|||
import com.newsblur.network.APIManager
|
||||
import com.newsblur.service.NBSyncService
|
||||
import com.newsblur.util.AppConstants
|
||||
import com.newsblur.util.UIUtils
|
||||
import com.newsblur.util.executeAsyncTask
|
||||
import dagger.hilt.android.AndroidEntryPoint
|
||||
import java.util.*
|
||||
import java.util.Collections
|
||||
import javax.inject.Inject
|
||||
|
||||
@AndroidEntryPoint
|
||||
|
@ -88,14 +87,14 @@ class AddFeedFragment : DialogFragment() {
|
|||
binding.inputFolderName.text.clear()
|
||||
addFeed(activity, apiManager, folderName)
|
||||
} else {
|
||||
UIUtils.safeToast(activity, R.string.add_folder_error, Toast.LENGTH_SHORT)
|
||||
Toast.makeText(activity, R.string.add_folder_error, Toast.LENGTH_SHORT).show()
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
private fun addFeed(activity: Activity, apiManager: APIManager, folderName: String?) {
|
||||
binding.textSyncStatus.visibility = View.VISIBLE
|
||||
binding.containerSyncStatus.visibility = View.VISIBLE
|
||||
lifecycleScope.executeAsyncTask(
|
||||
doInBackground = {
|
||||
(activity as AddFeedProgressListener).addFeedStarted()
|
||||
|
@ -103,7 +102,7 @@ class AddFeedFragment : DialogFragment() {
|
|||
apiManager.addFeed(feedUrl, folderName)
|
||||
},
|
||||
onPostExecute = {
|
||||
binding.textSyncStatus.visibility = View.GONE
|
||||
binding.containerSyncStatus.visibility = View.GONE
|
||||
val intent = Intent(activity, Main::class.java)
|
||||
intent.flags = Intent.FLAG_ACTIVITY_CLEAR_TOP
|
||||
if (!it.isError) {
|
||||
|
@ -111,7 +110,7 @@ class AddFeedFragment : DialogFragment() {
|
|||
NBSyncService.forceFeedsFolders()
|
||||
intent.putExtra(Main.EXTRA_FORCE_SHOW_FEED_ID, it.feed.feedId)
|
||||
} else {
|
||||
UIUtils.safeToast(activity, R.string.add_feed_error, Toast.LENGTH_SHORT)
|
||||
Toast.makeText(activity, R.string.add_feed_error, Toast.LENGTH_SHORT).show()
|
||||
}
|
||||
activity.startActivity(intent)
|
||||
activity.finish()
|
||||
|
@ -119,8 +118,7 @@ class AddFeedFragment : DialogFragment() {
|
|||
)
|
||||
}
|
||||
|
||||
private class AddFeedAdapter
|
||||
constructor(private val listener: OnFolderClickListener) : RecyclerView.Adapter<FolderViewHolder>() {
|
||||
private class AddFeedAdapter(private val listener: OnFolderClickListener) : RecyclerView.Adapter<FolderViewHolder>() {
|
||||
|
||||
private val folders: MutableList<Folder> = ArrayList()
|
||||
|
||||
|
@ -145,7 +143,7 @@ class AddFeedFragment : DialogFragment() {
|
|||
Collections.sort(folders, Folder.FolderComparator)
|
||||
this.folders.clear()
|
||||
this.folders.addAll(folders)
|
||||
notifyDataSetChanged()
|
||||
this.notifyDataSetChanged()
|
||||
}
|
||||
|
||||
class FolderViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
|
||||
|
|
|
@ -6,17 +6,33 @@
|
|||
android:animateLayoutChanges="true"
|
||||
android:orientation="vertical">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/text_sync_status"
|
||||
<androidx.appcompat.widget.LinearLayoutCompat
|
||||
android:id="@+id/container_sync_status"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="@color/status_overlay_background"
|
||||
android:gravity="center"
|
||||
android:padding="2dp"
|
||||
android:text="@string/sync_status_feed_add"
|
||||
android:textColor="@color/status_overlay_text"
|
||||
android:textSize="14sp"
|
||||
android:visibility="gone" />
|
||||
android:orientation="horizontal"
|
||||
android:paddingVertical="1dp"
|
||||
android:visibility="gone">
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center"
|
||||
android:text="@string/sync_status_feed_add"
|
||||
android:textColor="@color/status_overlay_text"
|
||||
android:textSize="14sp" />
|
||||
|
||||
<com.google.android.material.progressindicator.CircularProgressIndicator
|
||||
style="?circleProgressIndicator"
|
||||
android:layout_width="20dp"
|
||||
android:layout_height="20dp"
|
||||
android:layout_gravity="center"
|
||||
android:layout_marginStart="4dp"
|
||||
android:indeterminate="true" />
|
||||
|
||||
</androidx.appcompat.widget.LinearLayoutCompat>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/text_add_folder_title"
|
||||
|
@ -45,10 +61,10 @@
|
|||
android:layout_marginEnd="8dp"
|
||||
android:layout_weight="1"
|
||||
android:autofillHints="@null"
|
||||
android:textSize="14sp"
|
||||
android:hint="@string/new_folder_name_hint"
|
||||
android:inputType="textCapSentences"
|
||||
android:maxLines="1" />
|
||||
android:maxLines="1"
|
||||
android:textSize="14sp" />
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/ic_create_folder"
|
||||
|
|
|
@ -581,7 +581,7 @@
|
|||
<string name="sync_status_text">Storing text for %s stories…</string>
|
||||
<string name="sync_status_images">Storing %s images…</string>
|
||||
<string name="sync_status_offline">Offline</string>
|
||||
<string name="sync_status_feed_add">Adding feed …</string>
|
||||
<string name="sync_status_feed_add">Adding feed</string>
|
||||
|
||||
<string name="volume_key_navigation">Volume key navigation…</string>
|
||||
<string name="off">Off</string>
|
||||
|
|
Loading…
Add table
Reference in a new issue