Skip to content

Commit

Permalink
31
Browse files Browse the repository at this point in the history
31
  • Loading branch information
umerov1999 committed Jun 8, 2023
1 parent f50def9 commit 0f1f73d
Show file tree
Hide file tree
Showing 50 changed files with 1,615 additions and 1,176 deletions.
3 changes: 2 additions & 1 deletion app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/Constants.kt
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ object Constants {
const val UPLOAD_TIMEOUT = 3600L
const val DOWNLOAD_TIMEOUT = 3600L
const val GIF_TIMEOUT = 5L
const val LONGPOLL_TIMEOUT = 25L
const val LONGPOLL_TIMEOUT = 45L
const val LONGPOLL_WAIT = 25L
const val PICASSO_TIMEOUT = 15L
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ class StickersInteractor(private val networker: INetworker, private val storage:
it
)
}).setActive(true).setPurchased(true)
if (items.items.isNullOrEmpty()) {
Settings.get().other().del_last_sticker_sets_custom_sync(accountId)
}
storage.storeStickerSetsCustom(accountId, listOf(temp))
}
}
Expand All @@ -56,6 +59,9 @@ class StickersInteractor(private val networker: INetworker, private val storage:
list.reverse()
}
val ret = mapAllMutable(list) { mapStickerSet(it) }
if (list.isEmpty()) {
Settings.get().other().del_last_sticker_sets_sync(accountId)
}
storage.storeStickerSets(accountId, ret)
}
}
Expand All @@ -81,6 +87,9 @@ class StickersInteractor(private val networker: INetworker, private val storage:
}
temp.add(StickersKeywordsEntity(stickersKeywords, userStickers))
}
if (list.isEmpty()) {
Settings.get().other().del_last_sticker_keywords_sync(accountId)
}
storage.storeKeyWords(accountId, temp)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,17 +66,7 @@ class AudiosLocalFragment : BaseMvpFragment<AudiosLocalPresenter, IAudiosLocalVi
searchView.setQuery("", true)
searchView.setOnAdditionalButtonClickListener(object : OnAdditionalButtonClickListener {
override fun onAdditionalButtonClick() {
LocalAudioAlbumsFragment.newInstance(
object : LocalAudioAlbumsFragment.Listener {
override fun onSelected(bucket_id: Int) {
presenter?.fireBucketSelected(
bucket_id
)
}

}).show(
childFragmentManager, "audio_albums_local"
)
presenter?.fireLocalAudioAlbums()
}

})
Expand Down Expand Up @@ -155,6 +145,23 @@ class AudiosLocalFragment : BaseMvpFragment<AudiosLocalPresenter, IAudiosLocalVi
}
}

override fun goToLocalAudioAlbums(selectedId: Int) {
LocalAudioAlbumsFragment.newInstance(selectedId,
object : LocalAudioAlbumsFragment.Listener {
override fun onSelected(bucket_id: Int) {
if (Settings.get().other().isRememberLocalAudioAlbum) {
Settings.get().other().currentLocalAudioAlbum = bucket_id
}
presenter?.fireBucketSelected(
bucket_id
)
}

}).show(
childFragmentManager, "audio_albums_local"
)
}

override fun setUploadDataVisible(visible: Boolean) {
mUploadRoot?.visibility = if (visible) View.VISIBLE else View.GONE
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class AudiosLocalPresenter(accountId: Long, savedInstanceState: Bundle?) :
private var query: String? = null
private var errorPermissions = false
private var doAudioLoadTabs = false
private var bucket_id = 0
private var bucket_id: Int
fun fireBucketSelected(bucket_id: Int) {
this.bucket_id = bucket_id
fireRefresh()
Expand Down Expand Up @@ -76,6 +76,10 @@ class AudiosLocalPresenter(accountId: Long, savedInstanceState: Bundle?) :
fireRefresh()
}

fun fireLocalAudioAlbums() {
view?.goToLocalAudioAlbums(bucket_id)
}

fun setLoadingNow(loadingNow: Boolean) {
this.loadingNow = loadingNow
resolveRefreshingView()
Expand Down Expand Up @@ -364,5 +368,11 @@ class AudiosLocalPresenter(accountId: Long, savedInstanceState: Bundle?) :
uploadsData = ArrayList(0)
audios = ArrayList()
origin_audios = ArrayList()

bucket_id = if (Settings.get().other().isRememberLocalAudioAlbum) {
Settings.get().other().currentLocalAudioAlbum
} else {
0
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,6 @@ interface IAudiosLocalView : IMvpView, IErrorView, IToastView {
fun displayUploads(data: List<Upload>)
fun displayRefreshing(refreshing: Boolean)
fun checkPermission()

fun goToLocalAudioAlbums(selectedId: Int)
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,6 @@ interface ILocalAudioAlbumsView : IMvpView {
fun openAlbum(album: LocalImageAlbum)
fun notifyDataChanged()
fun requestReadExternalStoragePermission()

fun updateCurrentId(currentId: Int)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
package dev.ragnarok.fenrir.fragment.audio.local.localaudioalbums

import android.content.Context
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import dev.ragnarok.fenrir.R
import dev.ragnarok.fenrir.model.LocalImageAlbum
import dev.ragnarok.fenrir.module.FenrirNative
import dev.ragnarok.fenrir.picasso.Content_Local
import dev.ragnarok.fenrir.picasso.PicassoInstance.Companion.buildUriForPicasso
import dev.ragnarok.fenrir.picasso.PicassoInstance.Companion.with
import dev.ragnarok.fenrir.settings.CurrentTheme
import dev.ragnarok.fenrir.settings.Settings
import dev.ragnarok.fenrir.util.Utils
import dev.ragnarok.fenrir.view.natives.rlottie.RLottieImageView

class LocalAudioAlbumsAdapter(
context: Context,
private var data: List<LocalImageAlbum>
) : RecyclerView.Adapter<LocalAudioAlbumsAdapter.Holder>() {
private val isDark: Boolean = Settings.get().ui().isDarkModeEnabled(context)
private var clickListener: ClickListener? = null
private var currentId: Int = -1
fun setData(data: List<LocalImageAlbum>) {
this.data = data
notifyDataSetChanged()
}

fun updateCurrentId(currentId: Int) {
this.currentId = currentId
notifyDataSetChanged()
}

override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): Holder {
return Holder(
LayoutInflater.from(parent.context)
.inflate(R.layout.local_audio_album_item, parent, false)
)
}

override fun onBindViewHolder(holder: Holder, position: Int) {
val album = data[position]
val uri = buildUriForPicasso(Content_Local.AUDIO, album.getCoverImageId())
if (album.getId() != 0) {
holder.title.text = album.getName()
holder.subtitle.text =
holder.itemView.context.getString(
R.string.local_audios_count,
album.getPhotoCount()
)
with()
.load(uri)
.tag(PICASSO_TAG)
.placeholder(if (isDark) R.drawable.generic_audio_nowplaying_dark else R.drawable.generic_audio_nowplaying_light)
.error(if (isDark) R.drawable.generic_audio_nowplaying_dark else R.drawable.generic_audio_nowplaying_light)
.into(holder.image)
} else {
with().cancelRequest(holder.image)
holder.image.setImageResource(if (isDark) R.drawable.generic_audio_nowplaying_dark else R.drawable.generic_audio_nowplaying_light)
holder.title.setText(R.string.all_audios)
holder.subtitle.text = ""
}
holder.itemView.setOnClickListener {
clickListener?.onClick(album)
}

val isSelected = currentId == album.getId()
holder.selected.visibility = if (isSelected) View.VISIBLE else View.GONE
if (Utils.hasMarshmallow() && FenrirNative.isNativeLoaded) {
if (isSelected) {
holder.selected.fromRes(
dev.ragnarok.fenrir_common.R.raw.theme_selected,
Utils.dp(120f),
Utils.dp(120f),
intArrayOf(
0x333333,
CurrentTheme.getColorWhiteContrastFix(holder.selected.context),
0x777777,
CurrentTheme.getColorPrimary(holder.selected.context),
0x999999,
CurrentTheme.getColorSecondary(holder.selected.context)
)
)
holder.selected.playAnimation()
} else {
holder.selected.clearAnimationDrawable()
}
} else {
if (isSelected) {
holder.selected.setImageResource(R.drawable.theme_select)
}
}
}

override fun getItemCount(): Int {
return data.size
}

fun setClickListener(clickListener: ClickListener?) {
this.clickListener = clickListener
}

interface ClickListener {
fun onClick(album: LocalImageAlbum)
}

class Holder(itemView: View) : RecyclerView.ViewHolder(itemView) {
val image: ImageView = itemView.findViewById(R.id.item_local_album_cover)
val title: TextView = itemView.findViewById(R.id.item_local_album_name)
val subtitle: TextView = itemView.findViewById(R.id.counter)
val selected: RLottieImageView = itemView.findViewById(R.id.selected)
}

companion object {
const val PICASSO_TAG = "LocalAudioAlbumsAdapter.TAG"
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -9,28 +9,30 @@ import androidx.recyclerview.widget.RecyclerView
import androidx.recyclerview.widget.StaggeredGridLayoutManager
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout
import com.google.android.material.bottomsheet.BottomSheetDialog
import com.google.android.material.materialswitch.MaterialSwitch
import dev.ragnarok.fenrir.Extra
import dev.ragnarok.fenrir.R
import dev.ragnarok.fenrir.fragment.base.BaseMvpBottomSheetDialogFragment
import dev.ragnarok.fenrir.fragment.base.core.IPresenterFactory
import dev.ragnarok.fenrir.fragment.photos.localimagealbums.LocalPhotoAlbumsAdapter
import dev.ragnarok.fenrir.listener.PicassoPauseOnScrollListener
import dev.ragnarok.fenrir.model.LocalImageAlbum
import dev.ragnarok.fenrir.picasso.Content_Local
import dev.ragnarok.fenrir.settings.Settings
import dev.ragnarok.fenrir.util.AppPerms.requestPermissionsAbs
import dev.ragnarok.fenrir.view.MySearchView

class LocalAudioAlbumsFragment :
BaseMvpBottomSheetDialogFragment<LocalAudioAlbumsPresenter, ILocalAudioAlbumsView>(),
LocalPhotoAlbumsAdapter.ClickListener, SwipeRefreshLayout.OnRefreshListener,
LocalAudioAlbumsAdapter.ClickListener, SwipeRefreshLayout.OnRefreshListener,
ILocalAudioAlbumsView {
private val requestReadPermission =
requestPermissionsAbs(arrayOf(Manifest.permission.READ_EXTERNAL_STORAGE)) {
lazyPresenter {
fireReadExternalStoregePermissionResolved()
fireReadExternalStoragePermissionResolved()
}
}
private var mRecyclerView: RecyclerView? = null
private var mAlbumsAdapter: LocalPhotoAlbumsAdapter? = null
private var mAlbumsAdapter: LocalAudioAlbumsAdapter? = null
private var listener: Listener? = null
override fun onCreateDialog(savedInstanceState: Bundle?): BottomSheetDialog {
val dialog = BottomSheetDialog(requireActivity(), theme)
Expand All @@ -47,6 +49,11 @@ class LocalAudioAlbumsFragment :
): View? {
val view = inflater.inflate(R.layout.fragment_local_albums_audio, container, false)
val mySearchView: MySearchView = view.findViewById(R.id.searchview)
val mRememberAudioAlbum: MaterialSwitch = view.findViewById(R.id.remember_audio_album)
mRememberAudioAlbum.isChecked = Settings.get().other().isRememberLocalAudioAlbum
mRememberAudioAlbum.setOnClickListener {
Settings.get().other().isRememberLocalAudioAlbum = mRememberAudioAlbum.isChecked
}
mySearchView.setRightButtonVisibility(false)
mySearchView.setLeftIcon(R.drawable.magnify)
mySearchView.setOnQueryTextListener(object : MySearchView.OnQueryTextListener {
Expand All @@ -73,7 +80,7 @@ class LocalAudioAlbumsFragment :
mRecyclerView?.layoutManager = manager
mRecyclerView?.addOnScrollListener(PicassoPauseOnScrollListener(LocalPhotoAlbumsAdapter.PICASSO_TAG))
mAlbumsAdapter =
LocalPhotoAlbumsAdapter(requireActivity(), emptyList(), Content_Local.AUDIO)
LocalAudioAlbumsAdapter(requireActivity(), emptyList())
mAlbumsAdapter?.setClickListener(this)
mRecyclerView?.adapter = mAlbumsAdapter
return view
Expand Down Expand Up @@ -108,10 +115,17 @@ class LocalAudioAlbumsFragment :
requestReadPermission.launch()
}

override fun updateCurrentId(currentId: Int) {
mAlbumsAdapter?.updateCurrentId(currentId)
}

override fun getPresenterFactory(saveInstanceState: Bundle?): IPresenterFactory<LocalAudioAlbumsPresenter> {
return object : IPresenterFactory<LocalAudioAlbumsPresenter> {
override fun create(): LocalAudioAlbumsPresenter {
val selectedId =
requireArguments().getInt(Extra.ALBUM_ID, 0)
return LocalAudioAlbumsPresenter(
selectedId,
saveInstanceState
)
}
Expand All @@ -123,9 +137,12 @@ class LocalAudioAlbumsFragment :
}

companion object {
fun newInstance(selectedId: Int, listener: Listener?): LocalAudioAlbumsFragment {
val args = Bundle()
args.putInt(Extra.ALBUM_ID, selectedId)

fun newInstance(listener: Listener?): LocalAudioAlbumsFragment {
val fragment = LocalAudioAlbumsFragment()
fragment.arguments = args
fragment.listener = listener
return fragment
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import dev.ragnarok.fenrir.util.Objects.safeEquals
import dev.ragnarok.fenrir.util.PersistentLogger
import java.util.Locale

class LocalAudioAlbumsPresenter(savedInstanceState: Bundle?) :
class LocalAudioAlbumsPresenter(private val currentId: Int, savedInstanceState: Bundle?) :
RxSupportPresenter<ILocalAudioAlbumsView>(savedInstanceState) {
private val mLocalImageAlbums: MutableList<LocalImageAlbum>
private val mLocalImageAlbums_Search: MutableList<LocalImageAlbum>
Expand Down Expand Up @@ -46,6 +46,7 @@ class LocalAudioAlbumsPresenter(savedInstanceState: Bundle?) :

override fun onGuiCreated(viewHost: ILocalAudioAlbumsView) {
super.onGuiCreated(viewHost)
viewHost.updateCurrentId(currentId)
if (!hasReadStoragePermission(applicationContext)) {
if (!permissionRequestedOnce) {
permissionRequestedOnce = true
Expand Down Expand Up @@ -129,7 +130,7 @@ class LocalAudioAlbumsPresenter(savedInstanceState: Bundle?) :
view?.openAlbum(album)
}

fun fireReadExternalStoregePermissionResolved() {
fun fireReadExternalStoragePermissionResolved() {
if (hasReadStoragePermission(applicationContext)) {
loadData()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -234,9 +234,6 @@ class DialogsFragment : BaseMvpFragment<DialogsPresenter, IDialogsView>(), IDial
)
}
}).attachToRecyclerView(mRecyclerView)
if (needHelp(HelperSimple.DIALOG_SEND_HELPER, 3)) {
showSnackbar(R.string.dialog_send_helper, true)
}
}
}

Expand Down Expand Up @@ -414,6 +411,10 @@ class DialogsFragment : BaseMvpFragment<DialogsPresenter, IDialogsView>(), IDial
}?.show()
}

override fun showDialogSendHelper() {
showSnackbar(R.string.dialog_send_helper, true)
}

override fun onAvatarClick(dialog: Dialog) {
presenter?.fireDialogAvatarClick(
dialog
Expand Down
Loading

0 comments on commit 0f1f73d

Please sign in to comment.