Fix loading home scections multiple times

This commit is contained in:
h4h13 2019-09-29 08:39:21 +05:30
parent b1c0f70f61
commit 3a7d3bfcfe
11 changed files with 59 additions and 32 deletions

View file

@ -18,7 +18,6 @@ import code.name.monkey.retromusic.mvp.presenter.HomePresenter
import code.name.monkey.retromusic.mvp.presenter.HomePresenter.HomePresenterImpl
import dagger.Module
import dagger.Provides
import javax.inject.Singleton
/**
* Created by hemanths on 2019-09-04.
@ -27,7 +26,6 @@ import javax.inject.Singleton
class HomeModule {
@Provides
@Singleton
fun providesHomePresenter(presenter: HomePresenterImpl): HomePresenter {
return presenter
}

View file

@ -18,6 +18,7 @@ import android.app.Dialog
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.DialogFragment
import code.name.monkey.retromusic.R
import code.name.monkey.retromusic.activities.MainActivity
@ -78,6 +79,15 @@ class OptionsSheetDialogFragment : DialogFragment(), View.OnClickListener {
return materialDialog
}
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
dialog?.window?.let {
(requireActivity() as MainActivity).setLightNavigationBar(true)
}
return super.onCreateView(inflater, container, savedInstanceState)
}
companion object {
private const val WHICH_ONE = "which_one"

View file

@ -1,5 +1,6 @@
package code.name.monkey.retromusic.fragments.mainactivity.folders;
import android.app.ActivityOptions;
import android.app.Dialog;
import android.content.Context;
import android.media.MediaScannerConnection;
@ -26,6 +27,7 @@ import androidx.recyclerview.widget.RecyclerView;
import com.afollestad.materialcab.MaterialCab;
import com.google.android.material.appbar.AppBarLayout;
import com.google.android.material.card.MaterialCardView;
import com.google.android.material.dialog.MaterialAlertDialogBuilder;
import com.google.android.material.snackbar.Snackbar;
import com.simplecityapps.recyclerview_fastscroll.views.FastScrollRecyclerView;
@ -62,6 +64,7 @@ import code.name.monkey.retromusic.misc.UpdateToastMediaScannerCompletionListene
import code.name.monkey.retromusic.misc.WrappedAsyncTaskLoader;
import code.name.monkey.retromusic.model.Song;
import code.name.monkey.retromusic.util.FileUtil;
import code.name.monkey.retromusic.util.NavigationUtil;
import code.name.monkey.retromusic.util.PreferenceUtil;
import code.name.monkey.retromusic.util.RetroColorUtil;
import code.name.monkey.retromusic.util.ViewUtil;
@ -84,6 +87,8 @@ public class FoldersFragment extends AbsMainActivityFragment implements
private View coordinatorLayout, container, empty;
private MaterialCardView toolbarContainer;
private Toolbar toolbar;
private BreadCrumbLayout breadCrumbs;
@ -238,6 +243,10 @@ public class FoldersFragment extends AbsMainActivityFragment implements
breadCrumbs.setDeactivatedContentColor(ToolbarContentTintHelper.toolbarSubtitleColor(requireActivity(),
ColorUtil.INSTANCE.darkenColor(primaryColor)));
appBarLayout.addOnOffsetChangedListener((appBarLayout, verticalOffset) -> getMainActivity().setLightStatusbar(!ATHUtil.INSTANCE.isWindowBackgroundDark(getContext())));
toolbar.setOnClickListener(v -> {
ActivityOptions options = ActivityOptions.makeSceneTransitionAnimation(getMainActivity(), toolbarContainer, getString(R.string.transition_toolbar));
NavigationUtil.goToSearch(getMainActivity(), options);
});
}
private void setUpBreadCrumbs() {

View file

@ -43,17 +43,21 @@ import kotlinx.android.synthetic.main.home_content.*
import java.io.File
import java.util.*
import javax.inject.Inject
import kotlin.collections.ArrayList
class BannerHomeFragment : AbsMainActivityFragment(), MainActivityFragmentCallbacks, HomeView {
private lateinit var homeAdapter: HomeAdapter
@Inject
lateinit var homePresenter: HomePresenter
private var disposable: CompositeDisposable = CompositeDisposable()
private lateinit var toolbar: Toolbar
override fun sections(sections: ArrayList<Home>) {
val finalList = sections.sortedWith(compareBy { it.priority })
homeAdapter.swapData(finalList)
recyclerView.apply {
layoutManager = LinearLayoutManager(mainActivity)
adapter = homeAdapter
}
if (sections.isEmpty()) {
showEmptyView()
} else {
@ -61,11 +65,6 @@ class BannerHomeFragment : AbsMainActivityFragment(), MainActivityFragmentCallba
}
}
@Inject
lateinit var homePresenter: HomePresenter
private var disposable: CompositeDisposable = CompositeDisposable()
private lateinit var toolbar: Toolbar
override fun onCreateView(inflater: LayoutInflater, viewGroup: ViewGroup?, savedInstanceState: Bundle?): View? {
return inflater.inflate(if (PreferenceUtil.getInstance(requireContext()).isHomeBanner) R.layout.fragment_banner_home else R.layout.fragment_home, viewGroup, false)
@ -102,7 +101,6 @@ class BannerHomeFragment : AbsMainActivityFragment(), MainActivityFragmentCallba
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
App.musicComponent.inject(this)
}
@ -136,8 +134,6 @@ class BannerHomeFragment : AbsMainActivityFragment(), MainActivityFragmentCallba
contentContainer.setBackgroundColor(ThemeStore.primaryColor(requireContext()))
setupToolbar()
homeAdapter = HomeAdapter(mainActivity, ArrayList(), displayMetrics)
checkPadding()
userImage.setOnClickListener {
@ -145,8 +141,16 @@ class BannerHomeFragment : AbsMainActivityFragment(), MainActivityFragmentCallba
}
titleWelcome.setTextColor(ThemeStore.textColorPrimary(requireContext()))
titleWelcome.text = String.format("%s", PreferenceUtil.getInstance(requireContext()).userName)
homePresenter.attachView(this)
homePresenter.loadSections()
homeAdapter = HomeAdapter(mainActivity, ArrayList(), displayMetrics)
recyclerView.apply {
layoutManager = LinearLayoutManager(mainActivity)
adapter = homeAdapter
}
}
private fun checkPadding() {
@ -210,7 +214,6 @@ class BannerHomeFragment : AbsMainActivityFragment(), MainActivityFragmentCallba
checkPadding()
}
private lateinit var homeAdapter: HomeAdapter
override fun onCreateOptionsMenu(menu: Menu, inflater: MenuInflater) {
super.onCreateOptionsMenu(menu, inflater)

View file

@ -45,7 +45,7 @@ interface HomePresenter : Presenter<HomeView> {
private val repository: Repository
) : PresenterImpl<HomeView>(), HomePresenter {
val hashSet: HashSet<Home> = HashSet()
private val hashSet: HashSet<Home> = HashSet()
override fun loadSections() {
loadRecentArtists()

View file

@ -6,5 +6,5 @@
android:viewportHeight="24">
<path
android:fillColor="@color/md_white_1000"
android:pathData="M9 11.75c-0.69 0-1.25 0.56 -1.25 1.25s0.56 1.25 1.25 1.25 1.25-0.56 1.25-1.25-0.56-1.25-1.25-1.25zm6 0c-0.69 0-1.25 0.56 -1.25 1.25s0.56 1.25 1.25 1.25 1.25-0.56 1.25-1.25-0.56-1.25-1.25-1.25zM12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm0 18c-4.41 0-8-3.59-8-8 0-0.29 0.02 -0.58 0.05 -0.86 2.36-1.05 4.23-2.98 5.21-5.37C11.07 8.33 14.05 10 17.42 10c0.78 0 1.53-0.09 2.25-0.26 0.21 0.71 0.33 1.47 0.33 2.26 0 4.41-3.59 8-8 8z" />
android:pathData="M10 20v-6h4v6h5v-8h3L12 3 2 12h3v8z" />
</vector>

View file

@ -6,5 +6,5 @@
android:viewportHeight="24">
<path
android:fillColor="@color/md_white_1000"
android:pathData="M10.25 13c0 0.69-0.56 1.25-1.25 1.25S7.75 13.69 7.75 13s0.56-1.25 1.25-1.25 1.25 0.56 1.25 1.25zM15 11.75c-0.69 0-1.25 0.56 -1.25 1.25s0.56 1.25 1.25 1.25 1.25-0.56 1.25-1.25-0.56-1.25-1.25-1.25zm7 0.25c0 5.52-4.48 10-10 10S2 17.52 2 12 6.48 2 12 2s10 4.48 10 10zM10.66 4.12C12.06 6.44 14.6 8 17.5 8c0.46 0 0.91-0.05 1.34-0.12C17.44 5.56 14.9 4 12 4c-0.46 0-0.91 0.05 -1.34 0.12 zM4.42 9.47c1.71-0.97 3.03-2.55 3.66-4.44C6.37 6 5.05 7.58 4.42 9.47zM20 12c0-0.78-0.12-1.53-0.33-2.24-0.7 0.15 -1.42 0.24 -2.17 0.24 -3.13 0-5.92-1.44-7.76-3.69C8.69 8.87 6.6 10.88 4 11.86c0.01 0.04 0 0.09 0 0.14 0 4.41 3.59 8 8 8s8-3.59 8-8z" />
android:pathData="M12 5.69l5 4.5V18h-2v-6H9v6H7v-7.81l5-4.5M12 3L2 12h3v8h6v-6h2v6h6v-8h3L12 3z" />
</vector>

View file

@ -34,12 +34,15 @@
android:id="@+id/toolbarContainer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginEnd="8dp"
android:layout_marginStart="@dimen/toolbar_margin_horizontal"
android:layout_marginTop="@dimen/toolbar_margin_vertical"
android:layout_marginEnd="@dimen/toolbar_margin_horizontal"
android:layout_marginBottom="@dimen/toolbar_margin_vertical"
app:cardBackgroundColor="?colorSurface"
app:cardCornerRadius="8dp"
app:cardElevation="0dp"
app:cardUseCompatPadding="true"
app:layout_scrollFlags="scroll|enterAlways"
app:layout_collapseMode="pin"
app:strokeColor="?dividerColor"
app:strokeWidth="1dp">
@ -49,8 +52,13 @@
<code.name.monkey.appthemehelper.common.views.ATEToolbar
android:id="@+id/toolbar"
style="@style/Toolbar"
app:title="@string/folders"
android:layout_width="match_parent"
android:layout_height="@dimen/toolbar_height"
android:background="?colorSurface"
app:contentInsetStart="0dp"
app:contentInsetStartWithNavigation="0dp"
app:popupTheme="?toolbarPopupTheme"
app:title="@string/search_hint"
app:titleMarginStart="0dp"
app:titleTextAppearance="@style/ToolbarTextAppearanceSearch"
tools:ignore="UnusedAttribute" />

View file

@ -25,8 +25,8 @@
android:id="@+id/playAction"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/button_margin_horizontal"
android:layout_marginEnd="@dimen/button_margin_horizontal"
android:layout_marginStart="4dp"
android:layout_marginEnd="4dp"
android:layout_weight="1"
android:paddingTop="@dimen/button_padding_vertical"
android:paddingBottom="@dimen/button_padding_vertical"
@ -42,8 +42,8 @@
android:id="@+id/shuffleAction"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/button_margin_horizontal"
android:layout_marginEnd="@dimen/button_margin_horizontal"
android:layout_marginStart="4dp"
android:layout_marginEnd="4dp"
android:layout_weight="1"
android:paddingTop="@dimen/button_padding_vertical"
android:paddingBottom="@dimen/button_padding_vertical"

View file

@ -170,6 +170,7 @@
<style name="TextViewHeadline4" parent="TextAppearance.MaterialComponents.Headline4">
<item name="android:fontFamily">@font/circular</item>
</style>
<style name="TextViewHeadline5" parent="TextAppearance.MaterialComponents.Headline5">
<item name="android:fontFamily">@font/circular</item>
</style>

View file

@ -6,15 +6,13 @@ import android.app.ActivityManager
import android.content.Context
import android.os.Build
import android.view.View
import android.view.View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR
import androidx.annotation.ColorInt
import androidx.appcompat.widget.Toolbar
import code.name.monkey.appthemehelper.util.ColorUtil
import code.name.monkey.appthemehelper.util.TintHelper
import code.name.monkey.appthemehelper.util.ToolbarContentTintHelper
import android.view.View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR
/**
* @author Karim Abou Zeid (kabouzeid)
*/