1
0
mirror of https://github.com/TwidereProject/Twidere-Android synced 2025-02-16 19:50:53 +01:00
This commit is contained in:
Mariotaku Lee 2017-10-05 11:50:35 +08:00
parent bfc9282b18
commit 74efc30740
No known key found for this signature in database
GPG Key ID: 15C10F89D7C33535
16 changed files with 166 additions and 134 deletions

View File

@ -185,6 +185,7 @@ public interface IntentConstants {
String EXTRA_CLEAR_BUTTON = "clear_button";
String EXTRA_PATH = "path";
String EXTRA_ACTION = "action";
String EXTRA_ACTIONS = "actions";
String EXTRA_FLAGS = "flags";
String EXTRA_INTENT = "intent";
String EXTRA_BLACKLIST = "blacklist";

View File

@ -51,6 +51,7 @@ import org.mariotaku.twidere.activity.iface.IControlBarActivity.ControlBarShowHi
import org.mariotaku.twidere.constant.*
import org.mariotaku.twidere.exception.NoAccountException
import org.mariotaku.twidere.fragment.*
import org.mariotaku.twidere.fragment.drafts.DraftsFragment
import org.mariotaku.twidere.fragment.filter.FiltersFragment
import org.mariotaku.twidere.fragment.filter.FiltersImportBlocksFragment
import org.mariotaku.twidere.fragment.filter.FiltersImportMutesFragment
@ -459,12 +460,6 @@ class LinkHandlerActivity : BaseActivity(), SystemWindowInsetsCallback, IControl
LINK_ID_ACCOUNTS -> {
setTitle(R.string.title_accounts)
}
LINK_ID_DRAFTS -> {
setTitle(R.string.title_drafts)
}
LINK_ID_FILTERS -> {
setTitle(R.string.title_filters)
}
LINK_ID_MAP -> {
setTitle(R.string.action_view_map)
}

View File

@ -0,0 +1,31 @@
/*
* Twidere - Twitter client for Android
*
* Copyright (C) 2012-2017 Mariotaku Lee <mariotaku.lee@gmail.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.mariotaku.twidere.extension
import android.support.v4.app.Fragment
/**
* Created by mariotaku on 2017/10/4.
*/
var Fragment.title: CharSequence?
get() = activity.title
set(value) {
activity.title
}

View File

@ -27,6 +27,7 @@ import android.support.v4.widget.SwipeRefreshLayout.OnRefreshListener
import android.view.*
import android.widget.AbsListView
import android.widget.ListAdapter
import com.bumptech.glide.RequestManager
import kotlinx.android.synthetic.main.fragment_content_listview.*
import kotlinx.android.synthetic.main.layout_content_fragment_common.*
import org.mariotaku.twidere.R
@ -45,9 +46,13 @@ import org.mariotaku.twidere.util.TwidereColorUtils
abstract class AbsContentListViewFragment<A : ListAdapter> : BaseFragment(),
OnRefreshListener, RefreshScrollTopInterface, ControlBarOffsetListener, ContentListSupport<A>,
AbsListView.OnScrollListener {
private lateinit var scrollHandler: ListViewScrollHandler<A>
// Data fields
private val systemWindowsInsets = Rect()
override lateinit var adapter: A
var refreshEnabled: Boolean
get() = swipeLayout.isEnabled
set(value) {
swipeLayout.isEnabled = value
}
protected open val overrideDivider: Drawable?
get() = ThemeUtils.getDrawableFromThemeAttribute(context, android.R.attr.listDivider)
@ -55,8 +60,10 @@ abstract class AbsContentListViewFragment<A : ListAdapter> : BaseFragment(),
protected val isProgressShowing: Boolean
get() = progressContainer.visibility == View.VISIBLE
override lateinit var adapter: A
// Data fields
private val systemWindowsInsets = Rect()
private lateinit var scrollHandler: ListViewScrollHandler<A>
override fun onControlBarOffsetChanged(activity: IControlBarActivity, offset: Float) {
updateRefreshProgressOffset()
@ -96,7 +103,7 @@ abstract class AbsContentListViewFragment<A : ListAdapter> : BaseFragment(),
}
override fun onLoadMoreContents(@ILoadMoreSupportAdapter.IndicatorPosition position: Long) {
setRefreshEnabled(false)
refreshEnabled = false
}
override fun onAttach(context: Context) {
@ -125,7 +132,7 @@ abstract class AbsContentListViewFragment<A : ListAdapter> : BaseFragment(),
R.color.bg_refresh_progress_color_light, R.color.bg_refresh_progress_color_dark)
swipeLayout.setOnRefreshListener(this)
swipeLayout.setProgressBackgroundColorSchemeResource(colorRes)
adapter = onCreateAdapter(context)
adapter = onCreateAdapter(context, requestManager)
listView.setOnTouchListener { _, event ->
if (event.actionMasked == MotionEvent.ACTION_DOWN) {
updateRefreshProgressOffset()
@ -160,15 +167,11 @@ abstract class AbsContentListViewFragment<A : ListAdapter> : BaseFragment(),
updateRefreshProgressOffset()
}
fun setRefreshEnabled(enabled: Boolean) {
swipeLayout.isEnabled = enabled
}
override fun triggerRefresh(): Boolean {
return false
}
protected abstract fun onCreateAdapter(context: Context): A
protected abstract fun onCreateAdapter(context: Context, requestManager: RequestManager): A
protected fun showContent() {
errorContainer.visibility = View.GONE

View File

@ -33,6 +33,7 @@ import android.view.MenuItem
import android.view.View
import android.widget.AdapterView
import android.widget.AdapterView.AdapterContextMenuInfo
import com.bumptech.glide.RequestManager
import kotlinx.android.synthetic.main.fragment_content_listview.*
import org.mariotaku.ktextension.isNullOrEmpty
import org.mariotaku.ktextension.setItemAvailability
@ -55,7 +56,7 @@ class ExtensionsListFragment : AbsContentListViewFragment<ExtensionsAdapter>(),
showProgress()
}
override fun onCreateAdapter(context: Context): ExtensionsAdapter {
override fun onCreateAdapter(context: Context, requestManager: RequestManager): ExtensionsAdapter {
return ExtensionsAdapter(activity, requestManager)
}

View File

@ -35,6 +35,7 @@ import android.widget.CompoundButton
import android.widget.CompoundButton.OnCheckedChangeListener
import android.widget.ListView
import android.widget.TextView
import com.bumptech.glide.RequestManager
import kotlinx.android.synthetic.main.dialog_add_host_mapping.*
import kotlinx.android.synthetic.main.dialog_user_list_detail_editor.*
import kotlinx.android.synthetic.main.fragment_content_listview.*
@ -63,7 +64,7 @@ class HostMappingsListFragment : AbsContentListViewFragment<HostMappingsListFrag
reloadHostMappings()
}
override fun onCreateAdapter(context: Context): HostMappingAdapter {
override fun onCreateAdapter(context: Context, requestManager: RequestManager): HostMappingAdapter {
return HostMappingAdapter(activity)
}

View File

@ -26,6 +26,7 @@ import android.support.v4.app.hasRunningLoadersSafe
import android.support.v4.content.Loader
import android.view.View
import android.widget.AdapterView
import com.bumptech.glide.RequestManager
import com.squareup.otto.Subscribe
import kotlinx.android.synthetic.main.fragment_content_listview.*
import org.mariotaku.microblog.library.twitter.model.ResponseList
@ -69,7 +70,7 @@ class SavedSearchesListFragment : AbsContentListViewFragment<SavedSearchesAdapte
bus.register(this)
}
override fun onCreateAdapter(context: Context): SavedSearchesAdapter {
override fun onCreateAdapter(context: Context, requestManager: RequestManager): SavedSearchesAdapter {
return SavedSearchesAdapter(activity)
}

View File

@ -29,6 +29,7 @@ import android.support.v4.content.Loader
import android.view.View
import android.widget.AdapterView
import android.widget.ListView
import com.bumptech.glide.RequestManager
import com.squareup.otto.Subscribe
import kotlinx.android.synthetic.main.fragment_content_listview.*
import org.mariotaku.kpreferences.get
@ -71,7 +72,7 @@ class TrendsSuggestionsFragment : AbsContentListViewFragment<TrendsAdapter>(), L
showProgress()
}
override fun onCreateAdapter(context: Context): TrendsAdapter {
override fun onCreateAdapter(context: Context, requestManager: RequestManager): TrendsAdapter {
return TrendsAdapter(activity)
}

View File

@ -0,0 +1,57 @@
/*
* Twidere - Twitter client for Android
*
* Copyright (C) 2012-2017 Mariotaku Lee <mariotaku.lee@gmail.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.mariotaku.twidere.fragment.drafts
import android.os.Bundle
import org.mariotaku.ktextension.Bundle
import org.mariotaku.twidere.R
import org.mariotaku.twidere.adapter.SupportTabsAdapter
import org.mariotaku.twidere.constant.IntentConstants.EXTRA_ACTIONS
import org.mariotaku.twidere.extension.title
import org.mariotaku.twidere.fragment.AbsToolbarTabPagesFragment
import org.mariotaku.twidere.model.Draft
/**
* Created by mariotaku on 2017/10/4.
*/
class DraftsFragment : AbsToolbarTabPagesFragment() {
override fun onActivityCreated(savedInstanceState: Bundle?) {
super.onActivityCreated(savedInstanceState)
title = getString(R.string.title_drafts)
}
override fun addTabs(adapter: SupportTabsAdapter) {
adapter.add(DraftsListFragment::class.java, Bundle {
putStringArray(EXTRA_ACTIONS, null)
}, getString(R.string.label_drafts_all))
adapter.add(DraftsListFragment::class.java, Bundle {
putStringArray(EXTRA_ACTIONS, arrayOf(Draft.Action.UPDATE_STATUS,
Draft.Action.UPDATE_STATUS_COMPAT_1, Draft.Action.UPDATE_STATUS_COMPAT_2,
Draft.Action.QUOTE, Draft.Action.REPLY))
}, getString(R.string.label_drafts_statuses))
adapter.add(DraftsListFragment::class.java, Bundle {
putStringArray(EXTRA_ACTIONS, arrayOf(Draft.Action.SEND_DIRECT_MESSAGE,
Draft.Action.SEND_DIRECT_MESSAGE_COMPAT, Draft.Action.FAVORITE,
Draft.Action.RETWEET))
}, getString(R.string.label_drafts_others))
}
}

View File

@ -1,26 +1,27 @@
/*
* Twidere - Twitter client for Android
*
* Copyright (C) 2012-2014 Mariotaku Lee <mariotaku.lee@gmail.com>
*
* Twidere - Twitter client for Android
*
* Copyright (C) 2012-2017 Mariotaku Lee <mariotaku.lee@gmail.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.mariotaku.twidere.fragment
package org.mariotaku.twidere.fragment.drafts
import android.app.Activity
import android.app.Dialog
import android.content.Context
import android.content.DialogInterface
import android.content.DialogInterface.OnClickListener
import android.content.Intent
@ -40,8 +41,10 @@ import android.widget.AbsListView.MultiChoiceModeListener
import android.widget.AdapterView
import android.widget.AdapterView.OnItemClickListener
import android.widget.ListView
import kotlinx.android.synthetic.main.fragment_drafts.*
import com.bumptech.glide.RequestManager
import kotlinx.android.synthetic.main.fragment_content_listview.*
import org.mariotaku.kpreferences.get
import org.mariotaku.ktextension.isEmpty
import org.mariotaku.ktextension.setItemAvailability
import org.mariotaku.sqliteqb.library.Expression
import org.mariotaku.sqliteqb.library.OrderBy
@ -54,6 +57,9 @@ import org.mariotaku.twidere.adapter.DraftsAdapter
import org.mariotaku.twidere.constant.IntentConstants
import org.mariotaku.twidere.constant.textSizeKey
import org.mariotaku.twidere.extension.*
import org.mariotaku.twidere.fragment.AbsContentListViewFragment
import org.mariotaku.twidere.fragment.BaseDialogFragment
import org.mariotaku.twidere.fragment.ProgressDialogFragment
import org.mariotaku.twidere.model.Draft
import org.mariotaku.twidere.model.analyzer.PurchaseFinished
import org.mariotaku.twidere.model.draft.QuoteStatusActionExtras
@ -64,26 +70,22 @@ import org.mariotaku.twidere.util.deleteDrafts
import org.mariotaku.twidere.util.premium.ExtraFeaturesService
import java.lang.ref.WeakReference
class DraftsFragment : BaseFragment(), LoaderCallbacks<Cursor?>, OnItemClickListener, MultiChoiceModeListener {
class DraftsListFragment : AbsContentListViewFragment<DraftsAdapter>(), LoaderCallbacks<Cursor?>,
OnItemClickListener, MultiChoiceModeListener {
private lateinit var adapter: DraftsAdapter
private var actionMode: ActionMode? = null
override fun onActivityCreated(savedInstanceState: Bundle?) {
super.onActivityCreated(savedInstanceState)
setHasOptionsMenu(true)
adapter = DraftsAdapter(activity, requestManager).apply {
textSize = preferences[textSizeKey].toFloat()
}
listView.adapter = adapter
listView.emptyView = emptyView
listView.onItemClickListener = this
listView.choiceMode = ListView.CHOICE_MODE_MULTIPLE_MODAL
listView.setMultiChoiceModeListener(this)
emptyIcon.setImageResource(R.drawable.ic_info_draft)
emptyText.setText(R.string.drafts_hint_messages)
refreshEnabled = false
loaderManager.initLoader(0, null, this)
setListShown(false)
showProgress()
}
override fun onStart() {
@ -101,21 +103,38 @@ class DraftsFragment : BaseFragment(), LoaderCallbacks<Cursor?>, OnItemClickList
}
}
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
return inflater.inflate(R.layout.fragment_drafts, container, false)
override fun setUserVisibleHint(isVisibleToUser: Boolean) {
super.setUserVisibleHint(isVisibleToUser)
if (!isVisibleToUser) {
actionMode?.finish()
}
}
override fun onCreateAdapter(context: Context, requestManager: RequestManager): DraftsAdapter {
return DraftsAdapter(activity, requestManager).apply {
textSize = preferences[textSizeKey].toFloat()
}
}
// MARK: Loader callbacks
override fun onCreateLoader(id: Int, args: Bundle?): Loader<Cursor?> {
val uri = Drafts.CONTENT_URI_UNSENT
val cols = Drafts.COLUMNS
val actions = arguments.getStringArray(EXTRA_ACTIONS)
val (selection, selectionArgs) = if (actions != null) {
Pair(Expression.inArgs(Drafts.ACTION_TYPE, actions.size).sql, actions)
} else Pair(null, null)
val orderBy = OrderBy(Drafts.TIMESTAMP, false).sql
return CursorLoader(activity, uri, cols, null, null, orderBy)
return CursorLoader(activity, uri, cols, selection, selectionArgs, orderBy)
}
override fun onLoadFinished(loader: Loader<Cursor?>, cursor: Cursor?) {
adapter.swapCursor(cursor)
setListShown(true)
if (cursor == null || cursor.isEmpty) {
showEmpty(R.drawable.ic_info_draft, getString(R.string.drafts_hint_messages))
} else {
showContent()
}
}
override fun onLoaderReset(loader: Loader<Cursor?>) {
@ -142,7 +161,9 @@ class DraftsFragment : BaseFragment(), LoaderCallbacks<Cursor?>, OnItemClickList
return false
}
override fun onCreateActionMode(mode: ActionMode, menu: Menu): Boolean {
actionMode = mode
mode.menuInflater.inflate(R.menu.action_multi_select_drafts, menu)
listView.updateSelectionItems(menu)
return true
@ -185,10 +206,9 @@ class DraftsFragment : BaseFragment(), LoaderCallbacks<Cursor?>, OnItemClickList
}
override fun onDestroyActionMode(mode: ActionMode) {
actionMode = null
}
override fun onItemCheckedStateChanged(mode: ActionMode, position: Int, id: Long,
checked: Boolean) {
updateTitle(mode)
@ -216,12 +236,6 @@ class DraftsFragment : BaseFragment(), LoaderCallbacks<Cursor?>, OnItemClickList
}
}
fun setListShown(listShown: Boolean) {
listContainer.visibility = if (listShown) View.VISIBLE else View.GONE
progressContainer.visibility = if (listShown) View.GONE else View.VISIBLE
emptyView.visibility = if (listShown && adapter.isEmpty) View.VISIBLE else View.GONE
}
private fun editUpdateStatusDraft(draft: Draft): Boolean {
val intent = Intent(INTENT_ACTION_EDIT_DRAFT).apply {
`package` = BuildConfig.APPLICATION_ID

View File

@ -37,6 +37,7 @@ import android.widget.AbsListView
import android.widget.AbsListView.MultiChoiceModeListener
import android.widget.ListView
import android.widget.TextView
import com.bumptech.glide.RequestManager
import kotlinx.android.synthetic.main.fragment_content_listview.*
import org.mariotaku.ktextension.Bundle
import org.mariotaku.ktextension.set
@ -87,7 +88,7 @@ abstract class BaseFiltersFragment : AbsContentListViewFragment<SimpleCursorAdap
}
listView.setMultiChoiceModeListener(this)
loaderManager.initLoader(0, null, this)
setRefreshEnabled(false)
refreshEnabled = false
showProgress()
}
@ -208,7 +209,7 @@ abstract class BaseFiltersFragment : AbsContentListViewFragment<SimpleCursorAdap
return super.onOptionsItemSelected(item)
}
override fun onCreateAdapter(context: Context): SimpleCursorAdapter {
override fun onCreateAdapter(context: Context, requestManager: RequestManager): SimpleCursorAdapter {
return FilterListAdapter(context)
}

View File

@ -18,6 +18,7 @@ import android.text.Spanned
import android.view.*
import android.widget.ImageView
import android.widget.TextView
import com.bumptech.glide.RequestManager
import kotlinx.android.synthetic.main.fragment_content_listview.*
import nl.komponents.kovenant.then
import nl.komponents.kovenant.ui.alwaysUi
@ -164,7 +165,7 @@ class FilteredUsersFragment : BaseFiltersFragment() {
return super.onActionItemClicked(mode, item)
}
override fun onCreateAdapter(context: Context): SimpleCursorAdapter {
override fun onCreateAdapter(context: Context, requestManager: RequestManager): SimpleCursorAdapter {
return FilterUsersListAdapter(context)
}

View File

@ -22,6 +22,7 @@ package org.mariotaku.twidere.fragment.filter
import android.os.Bundle
import org.mariotaku.twidere.R
import org.mariotaku.twidere.adapter.SupportTabsAdapter
import org.mariotaku.twidere.extension.title
import org.mariotaku.twidere.fragment.AbsToolbarTabPagesFragment
class FiltersFragment : AbsToolbarTabPagesFragment() {
@ -29,6 +30,7 @@ class FiltersFragment : AbsToolbarTabPagesFragment() {
override fun onActivityCreated(savedInstanceState: Bundle?) {
super.onActivityCreated(savedInstanceState)
setHasOptionsMenu(true)
title = getString(R.string.title_filters)
}
override fun addTabs(adapter: SupportTabsAdapter) {

View File

@ -33,7 +33,7 @@ class StringExtraConfiguration(key: String, title: StringHolder, private val def
override fun onViewCreated(context: Context, view: View, fragment: CustomTabsFragment.TabEditorDialogFragment) {
super.onViewCreated(context, view, fragment)
editText = view.findViewById<EditText>(R.id.editText)
editText = view.findViewById(R.id.editText)
editText.hint = title.createString(context)
editText.setText(def)
}

View File

@ -1,80 +0,0 @@
<?xml version="1.0" encoding="utf-8"?><!--
~ Twidere - Twitter client for Android
~
~ Copyright (C) 2012-2015 Mariotaku Lee <mariotaku.lee@gmail.com>
~
~ This program is free software: you can redistribute it and/or modify
~ it under the terms of the GNU General Public License as published by
~ the Free Software Foundation, either version 3 of the License, or
~ (at your option) any later version.
~
~ This program is distributed in the hope that it will be useful,
~ but WITHOUT ANY WARRANTY; without even the implied warranty of
~ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
~ GNU General Public License for more details.
~
~ You should have received a copy of the GNU General Public License
~ along with this program. If not, see <http://www.gnu.org/licenses/>.
-->
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">
<FrameLayout
android:id="@+id/listContainer"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="gone"
tools:visibility="visible">
<ListView
android:id="@+id/listView"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:visibility="gone"/>
<LinearLayout
android:id="@+id/emptyView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical"
tools:visibility="visible">
<org.mariotaku.twidere.view.IconActionView
android:id="@+id/emptyIcon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:color="?android:textColorSecondary"/>
<org.mariotaku.twidere.view.FixedTextView
android:id="@+id/emptyText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="@dimen/element_spacing_normal"
android:gravity="center"
android:textAppearance="?android:textAppearanceMedium"/>
</LinearLayout>
</FrameLayout>
<FrameLayout
android:id="@+id/progressContainer"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="visible"
tools:visibility="gone">
<ProgressBar
android:id="@+id/loadProgress"
android:layout_width="@dimen/element_size_normal"
android:layout_height="@dimen/element_size_normal"
android:layout_gravity="center"
android:padding="@dimen/element_spacing_xsmall"/>
</FrameLayout>
</FrameLayout>

View File

@ -1364,4 +1364,7 @@
<string name="users_blocked">Blocked these users.</string>
<string name="users_lists_with_name"><xliff:g id="name">%s</xliff:g>\'s lists</string>
<string name="users_statuses">User\'s tweets</string>
<string name="label_drafts_all">All</string>
<string name="label_drafts_statuses">Tweets</string>
<string name="label_drafts_others">Others</string>
</resources>