Skip to content

Commit

Permalink
Merge pull request #37 from kylejwatson/refresh-feed
Browse files Browse the repository at this point in the history
Refresh feed
  • Loading branch information
zaguragit authored Jul 6, 2020
2 parents add85c0 + fbee1c8 commit 8bc6f80
Show file tree
Hide file tree
Showing 9 changed files with 63 additions and 6 deletions.
28 changes: 23 additions & 5 deletions app/src/main/java/posidon/launcher/Main.kt
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ import posidon.launcher.view.BottomDrawerBehavior.BottomSheetCallback
import posidon.launcher.view.ResizableLayout.OnResizeListener
import java.lang.ref.WeakReference
import java.util.*
import kotlin.collections.ArrayList
import kotlin.concurrent.thread
import kotlin.math.*
import kotlin.system.exitProcess
Expand Down Expand Up @@ -511,6 +512,7 @@ class Main : AppCompatActivity() {

private lateinit var desktop: NestedScrollView
private lateinit var feedRecycler: RecyclerView
private lateinit var feedProgressBar: ProgressBar

private lateinit var notifications: RecyclerView
private lateinit var widgetLayout: ResizableLayout
Expand Down Expand Up @@ -707,6 +709,8 @@ class Main : AppCompatActivity() {
layoutManager = LinearLayoutManager(this@Main)
isNestedScrollingEnabled = false
}
feedProgressBar = findViewById<ProgressBar>(R.id.feedProgressBar)
loadFeed()

notifications = findViewById<RecyclerView>(R.id.notifications).apply {
isNestedScrollingEnabled = false
Expand Down Expand Up @@ -862,11 +866,30 @@ class Main : AppCompatActivity() {
setDock()
}

fun updateFeed() {
if (feedProgressBar.visibility == VISIBLE || !Settings["feed:enabled", true]) return
feedProgressBar.visibility = VISIBLE
FeedLoader(object : FeedLoader.Listener {
override fun onFinished(feedModels: ArrayList<FeedItem>) {
(feedRecycler.adapter as FeedAdapter).updateFeed(feedModels)
feedProgressBar.visibility = GONE
}
}).execute()
}

private fun loadFeed() {
if (Settings["feed:enabled", true]) {
feedProgressBar.indeterminateDrawable.setColorFilter(accentColor, PorterDuff.Mode.SRC_IN )
feedRecycler.adapter = FeedAdapter(ArrayList(), this@Main)
updateFeed()
}
}

override fun onConfigurationChanged(newConfig: Configuration) {
super.onConfigurationChanged(newConfig)
onUpdate()
setDock()
loadFeed()
}

override fun onResume() {
Expand All @@ -885,11 +908,6 @@ class Main : AppCompatActivity() {
private fun onUpdate() {
val tmp = Tools.navbarHeight
updateNavbarHeight(this)
if (Settings["feed:enabled", true]) FeedLoader(object : FeedLoader.Listener {
override fun onFinished(feedModels: ArrayList<FeedItem>) {
feedRecycler.adapter = FeedAdapter(feedModels, this@Main)
}
}).execute()
if (Settings["notif:enabled", true]) {
NotificationService.onUpdate()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class CustomGestures : AppCompatActivity() {
Gestures.OPEN_APP_DRAWER -> 2
Gestures.OPEN_SEARCH -> 3
Gestures.OPEN_OVERVIEW -> 4
Gestures.REFRESH_FEED-> 5
else -> 0
}
setSelectionChangedListener {
Expand All @@ -36,6 +37,7 @@ class CustomGestures : AppCompatActivity() {
2 -> Gestures.OPEN_APP_DRAWER
3 -> Gestures.OPEN_SEARCH
4 -> Gestures.OPEN_OVERVIEW
5 -> Gestures.REFRESH_FEED
else -> ""
}
}
Expand All @@ -48,6 +50,7 @@ class CustomGestures : AppCompatActivity() {
Gestures.OPEN_APP_DRAWER -> 2
Gestures.OPEN_SEARCH -> 3
Gestures.OPEN_OVERVIEW -> 4
Gestures.REFRESH_FEED-> 5
else -> 0
}
setSelectionChangedListener {
Expand All @@ -56,6 +59,7 @@ class CustomGestures : AppCompatActivity() {
2 -> Gestures.OPEN_APP_DRAWER
3 -> Gestures.OPEN_SEARCH
4 -> Gestures.OPEN_OVERVIEW
5 -> Gestures.REFRESH_FEED
else -> ""
}
}
Expand All @@ -68,6 +72,7 @@ class CustomGestures : AppCompatActivity() {
Gestures.OPEN_APP_DRAWER -> 2
Gestures.OPEN_SEARCH -> 3
Gestures.OPEN_OVERVIEW -> 4
Gestures.REFRESH_FEED-> 5
else -> 0
}
setSelectionChangedListener {
Expand All @@ -76,6 +81,7 @@ class CustomGestures : AppCompatActivity() {
2 -> Gestures.OPEN_APP_DRAWER
3 -> Gestures.OPEN_SEARCH
4 -> Gestures.OPEN_OVERVIEW
5 -> Gestures.REFRESH_FEED
else -> ""
}
}
Expand All @@ -91,6 +97,7 @@ class CustomGestures : AppCompatActivity() {
Gestures.OPEN_APP_DRAWER -> 2
Gestures.OPEN_SEARCH -> 3
Gestures.OPEN_OVERVIEW -> 4
Gestures.REFRESH_FEED-> 5
else -> 0
}
setSelectionChangedListener {
Expand All @@ -99,6 +106,7 @@ class CustomGestures : AppCompatActivity() {
2 -> Gestures.OPEN_APP_DRAWER
3 -> Gestures.OPEN_SEARCH
4 -> Gestures.OPEN_OVERVIEW
5 -> Gestures.REFRESH_FEED
else -> ""
}
}
Expand All @@ -111,6 +119,7 @@ class CustomGestures : AppCompatActivity() {
Gestures.OPEN_APP_DRAWER -> 2
Gestures.OPEN_SEARCH -> 3
Gestures.OPEN_OVERVIEW -> 4
Gestures.REFRESH_FEED-> 5
else -> 0
}
setSelectionChangedListener {
Expand All @@ -119,6 +128,7 @@ class CustomGestures : AppCompatActivity() {
2 -> Gestures.OPEN_APP_DRAWER
3 -> Gestures.OPEN_SEARCH
4 -> Gestures.OPEN_OVERVIEW
5 -> Gestures.REFRESH_FEED
else -> ""
}
}
Expand Down
6 changes: 6 additions & 0 deletions app/src/main/java/posidon/launcher/feed/news/FeedAdapter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,12 @@ class FeedAdapter(private val feedModels: ArrayList<FeedItem>, private val conte

override fun getItemCount() = feedModels.size

fun updateFeed(feedModels: ArrayList<FeedItem>) {
this.feedModels.clear()
this.feedModels.addAll(feedModels)
this.notifyDataSetChanged()
}

companion object {
private val images: MutableMap<String?, Bitmap?> = HashMap()
}
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/java/posidon/launcher/tools/Gestures.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,15 @@ object Gestures {
const val OPEN_APP_DRAWER = "drawer"
const val OPEN_SEARCH = "search"
const val OPEN_OVERVIEW = "overview"
const val REFRESH_FEED = "refresh"

fun performTrigger(key: String) {
when (key) {
PULL_DOWN_NOTIFICATIONS -> Tools.publicContext!!.pullStatusbar()
OPEN_APP_DRAWER -> Main.instance.behavior.state = BottomDrawerBehavior.STATE_EXPANDED
OPEN_SEARCH -> Tools.publicContext!!.startActivity(Intent(Tools.publicContext, SearchActivity::class.java))
OPEN_OVERVIEW -> LauncherMenu.openOverview()
REFRESH_FEED -> Main.instance.updateFeed()
}
}
}
19 changes: 18 additions & 1 deletion app/src/main/res/layout/main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,17 @@
android:fadingEdgeLength="18dp"
android:requiresFadingEdge="vertical"
android:overScrollMode="always">
<LinearLayout
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">

<LinearLayout
android:id="@+id/desktopContent"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">


<posidon.launcher.view.ResizableLayout
android:id="@+id/widgets"
android:layout_width="match_parent"
Expand Down Expand Up @@ -75,11 +81,22 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:visibility="gone"/>

<androidx.recyclerview.widget.RecyclerView
android:id="@+id/feedrecycler"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</LinearLayout>
<ProgressBar
android:id="@+id/feedProgressBar"
style="?android:attr/progressBarStyleLarge"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="72dp"
android:indeterminateTint="@color/accent"
android:indeterminateTintMode="src_atop"
android:visibility="gone" />
</RelativeLayout>
</posidon.launcher.view.NestedScrollView>

<LinearLayout
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values-es/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -219,5 +219,6 @@
<item>Open app drawer</item>
<item>Open search</item>
<item>Open overview</item>
<item>Refresh feed</item>
</array>
</resources>
1 change: 1 addition & 0 deletions app/src/main/res/values-nl/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -218,5 +218,6 @@
<item>Open app drawer</item>
<item>Open search</item>
<item>Open overview</item>
<item>Refresh feed</item>
</array>
</resources>
1 change: 1 addition & 0 deletions app/src/main/res/values-ru/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -218,5 +218,6 @@
<item>Открыть app drawer</item>
<item>Открыть поиск</item>
<item>Открыть обзор</item>
<item>Refresh feed</item>
</array>
</resources>
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -218,5 +218,6 @@
<item>Open app drawer</item>
<item>Open search</item>
<item>Open overview</item>
<item>Refresh feed</item>
</array>
</resources>

0 comments on commit 8bc6f80

Please sign in to comment.