Skip to content

Commit

Permalink
Merge pull request #62 from ultranity/master
Browse files Browse the repository at this point in the history
Add feature: hide bookmarked pictures
  • Loading branch information
Notsfsssf authored Apr 27, 2020
2 parents 12b79a5 + dfa007f commit 74f87f8
Show file tree
Hide file tree
Showing 15 changed files with 139 additions and 46 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,11 @@ class UserMActivity : RinkActivity() {
when (item.itemId) {
android.R.id.home -> finishAfterTransition()
R.id.action_share -> share()
R.id.action_hideBookmarked -> {
viewModel.hideBookmarked.value = !viewModel.hideBookmarked.value!!
item.isChecked = !item.isChecked
mviewpager.adapter?.notifyDataSetChanged()
}
R.id.action_download -> {
// val intent =Intent(this,WorkActivity::class.java)
// intent.putExtra("id",id)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ class RecommendAdapter(
layoutResId: Int,
data: List<Illust>?,
private val R18on: Boolean,
var blockTags: List<String>
var blockTags: List<String>,
var hideBookmarked: Boolean = false
) :
BaseQuickAdapter<Illust, BaseViewHolder>(layoutResId, data?.toMutableList()), LoadMoreModule {

Expand Down Expand Up @@ -131,7 +132,14 @@ class RecommendAdapter(
break
}
}

if (hideBookmarked && item.is_bookmarked){
helper.itemView.visibility = View.GONE
helper.itemView.layoutParams.apply {
height = 0
width = 0
}
return
}
if (blockTags.isNotEmpty() && tags.isNotEmpty() && needBlock) {
helper.itemView.visibility = View.GONE
helper.itemView.layoutParams.apply {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,11 @@ class UserMPagerAdapter(
var newInstance: Fragment
) : FragmentStatePagerAdapter(fm, BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT) {


override fun getItemPosition(`object`: Any): Int {
return if (`object`.javaClass.name == "com.perol.asdpl.pixivez.fragments.UserIllustFragment") {
FragmentStatePagerAdapter.POSITION_NONE
} else super.getItemPosition(`object`)
}
/* override fun getItemCount() = 4
override fun createFragment(position: Int) = when (position) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,7 @@ class SearchSectionDialog : DialogFragment() {
val tms = Calendar.getInstance()
val thisMonth01 = "${tms.get(Calendar.YEAR)}-${tms.get(Calendar.MONTH) + 1}-01"
val halfYear01 = "${tms.get(Calendar.YEAR)}-${tms.get(Calendar.MONTH) + 1}-01"
var sort = arrayOf("date_desc", "date_asc", "popular_desc")
var search_target =
arrayOf("partial_match_for_tags", "exact_match_for_tags", "title_and_caption")


override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
val word = arguments?.getString("word", "")
Expand All @@ -64,8 +62,10 @@ class SearchSectionDialog : DialogFragment() {
)
val viewModel =
ViewModelProviders.of(requireParentFragment()).get(IllustfragmentViewModel::class.java)
var searchTargeti = viewModel.searchTarget.value
val first = view.findViewById<TabLayout>(R.id.tablayout_search_target).apply {
clearOnTabSelectedListeners()
searchTargeti?.let { getTabAt(it)?.select() }
addOnTabSelectedListener(object : TabLayout.OnTabSelectedListener {
override fun onTabReselected(tab: TabLayout.Tab?) {

Expand All @@ -76,13 +76,15 @@ class SearchSectionDialog : DialogFragment() {
}

override fun onTabSelected(tab: TabLayout.Tab) {
viewModel.searchTarget.value = search_target[tab.position]
searchTargeti = tab.position
}
})
}
var sorti = viewModel.sort.value
val second = view.findViewById<TabLayout>(R.id.tablayout_sort)
.apply {
clearOnTabSelectedListeners()
sorti?.let { getTabAt(it)?.select() }
addOnTabSelectedListener(object : TabLayout.OnTabSelectedListener {
override fun onTabReselected(tab: TabLayout.Tab?) {

Expand All @@ -93,7 +95,7 @@ class SearchSectionDialog : DialogFragment() {
}

override fun onTabSelected(tab: TabLayout.Tab) {
viewModel.sort.value = sort[tab.position]
sorti = tab.position
}
})
}
Expand All @@ -109,6 +111,13 @@ class SearchSectionDialog : DialogFragment() {
isChecked = viewModel.endDate.value != null && viewModel.startDate.value != null

}
var hideBookmarked = viewModel.hideBookmarked.value
val toggleShow= view.findViewById<ToggleButton>(R.id.toggleShow).apply {
isChecked = hideBookmarked == true
setOnCheckedChangeListener { buttonView, isChecked ->
hideBookmarked = isChecked
}
}
val button = view.findViewById<Button>(R.id.pick_button).apply {
var calendar = Calendar.getInstance()
if (viewModel.endDate.value != null) {
Expand Down Expand Up @@ -173,6 +182,9 @@ class SearchSectionDialog : DialogFragment() {

}
builder.setPositiveButton(android.R.string.ok) { p0, p1 ->
viewModel.hideBookmarked.value = hideBookmarked
viewModel.sort.value = sorti
viewModel.searchTarget.value = searchTargeti
if (word != null)
viewModel.firstSetData(word)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,13 +92,13 @@ class IllustFragment : BaseFragment(), AdapterView.OnItemSelectedListener {
Toasty.error(PxEZApp.instance, "not premium!").show()
viewModel.setPreview(param1!!, sort[position], null, null)
} else {
viewModel.sort.value = sort[position]
viewModel.sort.value = position
viewModel.firstSetData(param1!!)
}

}
} else {
viewModel.sort.value = sort[position]
viewModel.sort.value = position
viewModel.firstSetData(param1!!)
}
}
Expand Down Expand Up @@ -207,14 +207,14 @@ class IllustFragment : BaseFragment(), AdapterView.OnItemSelectedListener {
}*/
requireActivity().findViewById<TabLayout>(R.id.tablayout_searchresult)?.getTabAt(0)
?.view?.setOnClickListener {
if ((System.currentTimeMillis() - exitTime) > 3000) {
if ((System.currentTimeMillis() - exitTime) > 3000) {

exitTime = System.currentTimeMillis()
} else {
recyclerview_illust.smoothScrollToPosition(0)
}
exitTime = System.currentTimeMillis()
} else {
recyclerview_illust.smoothScrollToPosition(0)
}

}
}
}

private val starnum = intArrayOf(50000, 30000, 20000, 10000, 5000, 1000, 500, 250, 100, 0)
Expand Down Expand Up @@ -275,7 +275,11 @@ class IllustFragment : BaseFragment(), AdapterView.OnItemSelectedListener {
viewModel.isRefresh.observe(this, Observer {
swiperefresh.isRefreshing = it
})

viewModel.hideBookmarked.observe(this, Observer {
if (it != null) {
searchIllustAdapter.hideBookmarked = it
}
})
}

private fun addIllust(it: java.util.ArrayList<Illust>) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,15 @@ package com.perol.asdpl.pixivez.fragments

import android.os.Bundle
import android.view.LayoutInflater
import android.view.Menu
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.Fragment
import androidx.lifecycle.Observer
import androidx.lifecycle.ViewModelProvider
import androidx.recyclerview.widget.StaggeredGridLayoutManager
import com.perol.asdpl.pixivez.R
import com.perol.asdpl.pixivez.activity.UserMActivity
import com.perol.asdpl.pixivez.adapters.RecommendAdapter
import com.perol.asdpl.pixivez.objects.AdapterRefreshEvent
import com.perol.asdpl.pixivez.objects.BaseFragment
Expand Down Expand Up @@ -81,6 +83,7 @@ class UserIllustFragment : BaseFragment() {
mrecyclerview.layoutManager =
StaggeredGridLayoutManager(2, StaggeredGridLayoutManager.VERTICAL)
mrecyclerview.adapter = recommendAdapter
recommendAdapter.hideBookmarked = viewactivity.viewModel.hideBookmarked.value!!
}

// TODO: Rename and change types of parameters
Expand All @@ -102,6 +105,7 @@ class UserIllustFragment : BaseFragment() {
recommendAdapter.loadMoreComplete()
}
})
viewactivity = activity as UserMActivity
viewmodel.data.observe(this, Observer {
if (it != null) {
mrefreshlayout.isRefreshing = false
Expand All @@ -123,7 +127,7 @@ class UserIllustFragment : BaseFragment() {
}

lateinit var viewmodel: UserMillustViewModel

lateinit var viewactivity: UserMActivity

lateinit var recommendAdapter: RecommendAdapter
override fun onCreateView(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ class PxEZApp : Application() {
) { _, _ ->

}
sourceFile.delete()
Toasty.success(this, "${title}${getString(R.string.savesuccess)}", Toast.LENGTH_SHORT)
.show()
}
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/java/com/perol/asdpl/pixivez/services/Works.kt
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,10 @@ object Works {
val targetFile = File(path, filename)
try {
file.copyTo(targetFile, overwrite = true)
file.delete()
Toasty.success(
PxEZApp.instance,
PxEZApp.instance.resources.getString(R.string.savesuccess),
PxEZApp.instance.resources.getString(R.string.savesuccess)+"!",
Toast.LENGTH_SHORT
).show()
MediaScannerConnection.scanFile(
Expand All @@ -134,7 +135,6 @@ object Works {
} catch (e: Exception) {

}

}

fun imageDownloadAll(illust: Illust) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ fun Calendar?.generateDateString(): String? {

class IllustfragmentViewModel : BaseViewModel() {
var sortT = arrayOf("date_desc", "date_asc", "popular_desc")
var search_targetT =
var searchTargetT =
arrayOf("partial_match_for_tags", "exact_match_for_tags", "title_and_caption")

var illusts = MutableLiveData<ArrayList<Illust>>()
Expand All @@ -48,8 +48,9 @@ class IllustfragmentViewModel : BaseViewModel() {
var nexturl = MutableLiveData<String>()
var bookmarkid = MutableLiveData<Long>()
var isRefresh = MutableLiveData<Boolean>(false)
val sort = MutableLiveData<String>(sortT[0])
val searchTarget = MutableLiveData<String>(search_targetT[0])
var hideBookmarked = MutableLiveData<Boolean>(false)
val sort = MutableLiveData<Int>(0)
val searchTarget = MutableLiveData<Int>(0)
val startDate = MutableLiveData<Calendar>()
val endDate = MutableLiveData<Calendar>()
fun setPreview(word: String, sort: String, search_target: String?, duration: String?) {
Expand All @@ -74,8 +75,8 @@ class IllustfragmentViewModel : BaseViewModel() {

retrofitRespository.getSearchIllust(
word,
sort.value!!,
searchTarget.value!!,
sortT[sort.value!!],
searchTargetT[searchTarget.value!!],
startDate.value.generateDateString(),
endDate.value.generateDateString(),
null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ class UserMViewModel : BaseViewModel() {
var retrofitRespository = RetrofitRepository.getInstance()
var userDetail = MutableLiveData<UserDetailResponse>()
var isfollow = MutableLiveData<Boolean>()
var hideBookmarked = MutableLiveData<Boolean>(false)

fun getData(userid: Long) {
retrofitRespository.getUserDetail(userid).subscribe({
Expand Down
79 changes: 62 additions & 17 deletions app/src/main/res/layout/dialog_searchsection.xml
Original file line number Diff line number Diff line change
Expand Up @@ -132,24 +132,69 @@
android:layout_height="match_parent"
android:text="@string/a_year" />
</com.google.android.material.tabs.TabLayout>-->
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginStart="8dp"
android:layout_marginTop="5dp"
android:layout_marginEnd="8dp"
android:text="@string/choice_date"
android:textSize="16sp" />

<ToggleButton
android:id="@+id/toggle"
android:layout_margin="8dp"
android:layout_width="wrap_content"
android:contentDescription="@string/choice"
android:checked="false"
android:text="@string/choice_date"
android:layout_height="wrap_content" />
<TableLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">

<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent" >

<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginStart="8dp"
android:layout_marginTop="5dp"
android:layout_marginEnd="8dp"
android:text="@string/choice_date"
android:textSize="16sp" />

<Space
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1" />

<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginStart="8dp"
android:layout_marginTop="5dp"
android:layout_marginEnd="8dp"
android:text="@string/hide_bookmarked"
android:textSize="16sp" />
</TableRow>

<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent" >

<ToggleButton
android:id="@+id/toggle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="8dp"
android:checked="false"
android:contentDescription="@string/choice"
android:text="@string/choice_date" />

<Space
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1" />

<ToggleButton
android:id="@+id/toggleShow"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="8dp"
android:checked="false"
android:text="@string/hide_bookmarked" />
</TableRow>

</TableLayout>

<LinearLayout
android:id="@+id/pick_date_layout"
Expand Down
7 changes: 6 additions & 1 deletion app/src/main/res/menu/menu_userx.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,14 @@
<item
android:id="@+id/action_share"
android:icon="@drawable/ic_action_share"
app:iconTint="?android:textColorPrimaryInverse"
android:title="share"
app:iconTint="?android:textColorPrimaryInverse"
app:showAsAction="ifRoom" />
<item
android:id="@+id/action_hideBookmarked"
android:checkable="true"
android:title="@string/hide_bookmarked"
app:showAsAction="collapseActionView" />
<item
android:id="@+id/action_download"
android:title="Σ( ° △ °|||)︴"
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values-en/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,7 @@
<string name="start_date">Start Date</string>
<string name="end_date">End Date</string>
<string name="choice_date">Choice Date</string>
<string name="hide_bookmarked">Hide Bookmarked Pic</string>
<string name="create_painter_folder">Create a separate folder for each painter</string>
<string name="create_separate_folder">create separate folder</string>
<string name="refresh_token">refresh token</string>
Expand Down
Loading

0 comments on commit 74f87f8

Please sign in to comment.