diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/activity/PremiumDashboardActivity.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/activity/PremiumDashboardActivity.kt index 1a4b2241e..a72321b1c 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/activity/PremiumDashboardActivity.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/activity/PremiumDashboardActivity.kt @@ -31,6 +31,7 @@ import org.mariotaku.twidere.util.Analyzer import org.mariotaku.twidere.util.SharedPreferencesWrapper import org.mariotaku.twidere.util.dagger.GeneralComponentHelper import org.mariotaku.twidere.util.premium.ExtraFeaturesService +import org.mariotaku.twidere.util.schedule.StatusScheduleController import org.mariotaku.twidere.view.ContainerView import java.lang.ref.WeakReference import java.util.concurrent.atomic.AtomicBoolean @@ -167,6 +168,9 @@ class PremiumDashboardActivity : BaseActivity() { @Inject protected lateinit var preferences: SharedPreferencesWrapper + @Inject + protected lateinit var scheduleControllerFactory: StatusScheduleController.Factory + var position: Int = RecyclerView.NO_POSITION internal set diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/BaseFragment.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/BaseFragment.kt index 26ac9fc32..3dff70061 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/BaseFragment.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/BaseFragment.kt @@ -26,11 +26,13 @@ import android.support.v4.text.BidiFormatter import com.squareup.otto.Bus import com.twitter.Validator import nl.komponents.kovenant.Promise +import org.mariotaku.restfu.http.RestHttpClient import org.mariotaku.twidere.fragment.iface.IBaseFragment import org.mariotaku.twidere.model.DefaultFeatures import org.mariotaku.twidere.util.* import org.mariotaku.twidere.util.dagger.GeneralComponentHelper import org.mariotaku.twidere.util.premium.ExtraFeaturesService +import org.mariotaku.twidere.util.schedule.StatusScheduleController import javax.inject.Inject open class BaseFragment : Fragment(), IBaseFragment { @@ -64,6 +66,13 @@ open class BaseFragment : Fragment(), IBaseFragment { lateinit var permissionsManager: PermissionsManager @Inject lateinit var defaultFeatures: DefaultFeatures + @Inject + lateinit var statusScheduleControllerFactory: StatusScheduleController.Factory + @Inject + lateinit var restHttpClient: RestHttpClient + + protected val statusScheduleController: StatusScheduleController? + get() = statusScheduleControllerFactory.newInstance(context) private val actionHelper = IBaseFragment.ActionHelper(this) diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/DraftsFragment.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/DraftsFragment.kt index 5715d02f4..9de086337 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/DraftsFragment.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/DraftsFragment.kt @@ -19,6 +19,7 @@ package org.mariotaku.twidere.fragment +import android.app.Activity import android.app.Dialog import android.app.NotificationManager import android.content.Context @@ -44,6 +45,7 @@ import android.widget.ListView import com.bumptech.glide.Glide import kotlinx.android.synthetic.main.fragment_drafts.* import org.mariotaku.kpreferences.get +import org.mariotaku.ktextension.setItemAvailability import org.mariotaku.sqliteqb.library.Expression import org.mariotaku.twidere.R import org.mariotaku.twidere.TwidereConstants.* @@ -53,10 +55,13 @@ import org.mariotaku.twidere.constant.IntentConstants import org.mariotaku.twidere.constant.textSizeKey import org.mariotaku.twidere.extension.* import org.mariotaku.twidere.model.Draft +import org.mariotaku.twidere.model.analyzer.PurchaseFinished import org.mariotaku.twidere.provider.TwidereDataStore.Drafts import org.mariotaku.twidere.service.LengthyOperationsService +import org.mariotaku.twidere.util.Analyzer import org.mariotaku.twidere.util.AsyncTaskUtils import org.mariotaku.twidere.util.deleteDrafts +import org.mariotaku.twidere.util.premium.ExtraFeaturesService import java.lang.ref.WeakReference class DraftsFragment : BaseFragment(), LoaderCallbacks, OnItemClickListener, MultiChoiceModeListener { @@ -65,6 +70,7 @@ class DraftsFragment : BaseFragment(), LoaderCallbacks, OnItemClickList override fun onActivityCreated(savedInstanceState: Bundle?) { super.onActivityCreated(savedInstanceState) + setHasOptionsMenu(true) adapter = DraftsAdapter(activity, Glide.with(this)).apply { textSize = preferences[textSizeKey].toFloat() } @@ -85,6 +91,16 @@ class DraftsFragment : BaseFragment(), LoaderCallbacks, OnItemClickList super.onStart() } + override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { + when (requestCode) { + REQUEST_PURCHASE_EXTRA_FEATURES -> { + if (resultCode == Activity.RESULT_OK) { + Analyzer.log(PurchaseFinished.create(data!!)) + } + } + } + } + override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { return inflater.inflate(R.layout.fragment_drafts, container, false) } @@ -106,6 +122,32 @@ class DraftsFragment : BaseFragment(), LoaderCallbacks, OnItemClickList adapter.swapCursor(null) } + override fun onCreateOptionsMenu(menu: Menu, inflater: MenuInflater) { + inflater.inflate(R.menu.menu_drafts, menu) + } + + override fun onPrepareOptionsMenu(menu: Menu) { + val scheduleSupported = extraFeaturesService.isSupported(ExtraFeaturesService.FEATURE_SCHEDULE_STATUS) + menu.setItemAvailability(R.id.scheduled_statuses, scheduleSupported) + } + + override fun onOptionsItemSelected(item: MenuItem): Boolean { + when (item.itemId) { + R.id.scheduled_statuses -> { + if (extraFeaturesService.isEnabled(ExtraFeaturesService.FEATURE_SCHEDULE_STATUS)) { + val scheduleManageIntent = statusScheduleController?.createManageIntent() + startActivity(scheduleManageIntent) + } else { + ExtraFeaturesIntroductionDialogFragment.show(childFragmentManager, + ExtraFeaturesService.FEATURE_SCHEDULE_STATUS, + requestCode = REQUEST_PURCHASE_EXTRA_FEATURES) + } + return true + } + } + return false + } + override fun onCreateActionMode(mode: ActionMode, menu: Menu): Boolean { mode.menuInflater.inflate(R.menu.action_multi_select_drafts, menu) listView.updateSelectionItems(menu) diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/util/schedule/StatusScheduleController.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/util/schedule/StatusScheduleController.kt index c1eeda071..ecd1be0a5 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/util/schedule/StatusScheduleController.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/util/schedule/StatusScheduleController.kt @@ -41,6 +41,10 @@ interface StatusScheduleController { fun createSetScheduleIntent(): Intent + fun createSettingsIntent(): Intent? + + fun createManageIntent(): Intent? + class ScheduleException : UpdateStatusTask.UpdateStatusException { constructor() : super() diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/util/webkit/DefaultWebViewClient.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/util/webkit/DefaultWebViewClient.kt index a1f3ef57a..739b49436 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/util/webkit/DefaultWebViewClient.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/util/webkit/DefaultWebViewClient.kt @@ -1,18 +1,18 @@ /* - * Twidere - Twitter client for Android - * - * Copyright (C) 2012-2014 Mariotaku Lee - * + * Twidere - Twitter client for Android + * + * Copyright (C) 2012-2017 Mariotaku Lee + * * 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 . */ @@ -30,14 +30,14 @@ import org.mariotaku.twidere.util.Utils.showErrorMessage open class DefaultWebViewClient(val activity: A) : WebViewClient() { - @Deprecated("") + @Suppress("OverridingDeprecatedMember") override fun shouldOverrideUrlLoading(view: WebView, url: String): Boolean { + val uri = Uri.parse(url) try { - activity.startActivity(Intent(Intent.ACTION_VIEW, Uri.parse(url))) + activity.startActivity(Intent(Intent.ACTION_VIEW, uri)) } catch (e: ActivityNotFoundException) { showErrorMessage(activity, null, e, false) } - return true } } diff --git a/twidere/src/main/res/menu/menu_drafts.xml b/twidere/src/main/res/menu/menu_drafts.xml new file mode 100644 index 000000000..aced1bfe6 --- /dev/null +++ b/twidere/src/main/res/menu/menu_drafts.xml @@ -0,0 +1,28 @@ + + + + + + \ No newline at end of file diff --git a/twidere/src/main/res/values/strings.xml b/twidere/src/main/res/values/strings.xml index b86b08217..911331e7e 100644 --- a/twidere/src/main/res/values/strings.xml +++ b/twidere/src/main/res/values/strings.xml @@ -1123,7 +1123,9 @@ Block %s Blocked users Browser sign in + Buffer queue Schedule with Buffer + Buffer settings Compose Conversation Connect to… @@ -1261,4 +1263,5 @@ User\'s tweets Vibration + Scheduled tweets