improved media viewer theme
This commit is contained in:
parent
8cd2d6814f
commit
b50904c7ec
|
@ -173,7 +173,7 @@ dependencies {
|
|||
compile "com.github.mariotaku.CommonsLibrary:text:$mariotaku_commons_library_version"
|
||||
compile "com.github.mariotaku.CommonsLibrary:text-kotlin:$mariotaku_commons_library_version"
|
||||
compile 'com.github.mariotaku:KPreferences:0.9.5'
|
||||
compile 'com.github.mariotaku:Chameleon:0.9'
|
||||
compile 'com.github.mariotaku:Chameleon:0.9.1'
|
||||
compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
|
||||
compile 'nl.komponents.kovenant:kovenant:3.3.0'
|
||||
compile 'nl.komponents.kovenant:kovenant-android:3.3.0'
|
||||
|
|
|
@ -60,9 +60,9 @@ public interface IIconActionButton extends ChameleonView {
|
|||
public static Appearance create(Context context, AttributeSet attributeSet, Chameleon.Theme theme) {
|
||||
Appearance appearance = new Appearance();
|
||||
ChameleonTypedArray a = ChameleonTypedArray.obtain(context, attributeSet, R.styleable.IconActionButton, theme);
|
||||
appearance.setDefaultColor(a.getColor(R.styleable.IconActionButton_iabColor, 0));
|
||||
appearance.setActivatedColor(a.getColor(R.styleable.IconActionButton_iabActivatedColor, 0));
|
||||
appearance.setDisabledColor(a.getColor(R.styleable.IconActionButton_iabDisabledColor, 0));
|
||||
appearance.setDefaultColor(a.getColor(R.styleable.IconActionButton_iabColor, 0, false));
|
||||
appearance.setActivatedColor(a.getColor(R.styleable.IconActionButton_iabActivatedColor, 0, false));
|
||||
appearance.setDisabledColor(a.getColor(R.styleable.IconActionButton_iabDisabledColor, 0, false));
|
||||
a.recycle();
|
||||
return appearance;
|
||||
}
|
||||
|
|
|
@ -68,6 +68,7 @@ import javax.inject.Inject
|
|||
open class BaseActivity : ChameleonActivity(), IExtendedActivity, IThemedActivity,
|
||||
IControlBarActivity, OnFitSystemWindowsListener, SystemWindowsInsetsCallback,
|
||||
KeyboardShortcutCallback, OnPreferenceDisplayDialogCallback {
|
||||
|
||||
@Inject
|
||||
lateinit var keyboardShortcutsHandler: KeyboardShortcutsHandler
|
||||
@Inject
|
||||
|
|
|
@ -32,6 +32,7 @@ import android.view.Menu
|
|||
import android.view.MenuItem
|
||||
import android.widget.Toast
|
||||
import kotlinx.android.synthetic.main.activity_media_viewer.*
|
||||
import org.mariotaku.chameleon.Chameleon
|
||||
import org.mariotaku.ktextension.checkAllSelfPermissionsGranted
|
||||
import org.mariotaku.ktextension.toTypedArray
|
||||
import org.mariotaku.mediaviewer.library.*
|
||||
|
@ -65,14 +66,23 @@ class MediaViewerActivity : BaseActivity(), IExtendedActivity, IMediaViewerActiv
|
|||
private var saveToStoragePosition = -1
|
||||
private var shareMediaPosition = -1
|
||||
|
||||
private lateinit var mediaViewerHelper: IMediaViewerActivity.Helper
|
||||
|
||||
private var mHelper: IMediaViewerActivity.Helper? = null
|
||||
private val status: ParcelableStatus?
|
||||
get() = intent.getParcelableExtra<ParcelableStatus>(EXTRA_STATUS)
|
||||
|
||||
private val initialMedia: ParcelableMedia?
|
||||
get() = intent.getParcelableExtra<ParcelableMedia>(EXTRA_CURRENT_MEDIA)
|
||||
|
||||
private val media: Array<ParcelableMedia> by lazy {
|
||||
intent.getParcelableArrayExtra(EXTRA_MEDIA).toTypedArray(ParcelableMedia.CREATOR)
|
||||
}
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
GeneralComponentHelper.build(this).inject(this)
|
||||
mHelper = IMediaViewerActivity.Helper(this)
|
||||
mHelper!!.onCreate(savedInstanceState)
|
||||
mediaViewerHelper = IMediaViewerActivity.Helper(this)
|
||||
mediaViewerHelper.onCreate(savedInstanceState)
|
||||
val actionBar = supportActionBar!!
|
||||
actionBar.setDisplayHomeAsUpEnabled(true)
|
||||
}
|
||||
|
@ -88,15 +98,17 @@ class MediaViewerActivity : BaseActivity(), IExtendedActivity, IMediaViewerActiv
|
|||
|
||||
override fun onContentChanged() {
|
||||
super.onContentChanged()
|
||||
mHelper!!.onContentChanged()
|
||||
mediaViewerHelper.onContentChanged()
|
||||
}
|
||||
|
||||
override fun onCreateOptionsMenu(menu: Menu): Boolean {
|
||||
super.onCreateOptionsMenu(menu)
|
||||
menuInflater.inflate(R.menu.menu_media_viewer, menu)
|
||||
return true
|
||||
}
|
||||
|
||||
override fun onPrepareOptionsMenu(menu: Menu): Boolean {
|
||||
super.onPrepareOptionsMenu(menu)
|
||||
val viewPager = findViewPager()
|
||||
val adapter = viewPager.adapter
|
||||
val currentItem = viewPager.currentItem
|
||||
|
@ -265,14 +277,8 @@ class MediaViewerActivity : BaseActivity(), IExtendedActivity, IMediaViewerActiv
|
|||
return media.size
|
||||
}
|
||||
|
||||
private val status: ParcelableStatus?
|
||||
get() = intent.getParcelableExtra<ParcelableStatus>(EXTRA_STATUS)
|
||||
|
||||
private val initialMedia: ParcelableMedia?
|
||||
get() = intent.getParcelableExtra<ParcelableMedia>(EXTRA_CURRENT_MEDIA)
|
||||
|
||||
private val media: Array<ParcelableMedia> by lazy {
|
||||
intent.getParcelableArrayExtra(EXTRA_MEDIA).toTypedArray(ParcelableMedia.CREATOR)
|
||||
override fun getOverrideTheme(): Chameleon.Theme {
|
||||
return Chameleon.Theme.from(this)
|
||||
}
|
||||
|
||||
private fun processShareIntent(intent: Intent) {
|
||||
|
|
|
@ -18,15 +18,14 @@ import org.mariotaku.twidere.model.ParcelableMedia
|
|||
import org.mariotaku.twidere.model.UserKey
|
||||
import org.mariotaku.twidere.util.TwidereMathUtils
|
||||
import org.mariotaku.twidere.util.UriUtils
|
||||
import org.mariotaku.twidere.util.Utils
|
||||
import org.mariotaku.twidere.util.media.MediaExtra
|
||||
import java.io.IOException
|
||||
import java.io.InputStream
|
||||
|
||||
class ImagePageFragment : SubsampleImageViewerFragment() {
|
||||
private var mMediaLoadState: Int = 0
|
||||
|
||||
private var mediaLoadState: Int = 0
|
||||
private var mediaDownloadEvent: MediaDownloadEvent? = null
|
||||
private var resultCreator: CacheDownloadLoader.ResultCreator? = null
|
||||
private val sizedResultCreator: CacheDownloadLoader.ResultCreator by lazy { SizedResultCreator(context) }
|
||||
|
||||
override fun onActivityCreated(savedInstanceState: Bundle?) {
|
||||
super.onActivityCreated(savedInstanceState)
|
||||
|
@ -53,17 +52,12 @@ class ImagePageFragment : SubsampleImageViewerFragment() {
|
|||
return mediaExtra
|
||||
}
|
||||
|
||||
override fun getDownloadUri(): Uri? {
|
||||
val downloadUri = super.getDownloadUri() ?: return null
|
||||
return replaceTwitterMediaUri(downloadUri)
|
||||
}
|
||||
|
||||
override fun hasDownloadedData(): Boolean {
|
||||
return super.hasDownloadedData() && mMediaLoadState != State.ERROR
|
||||
return super.hasDownloadedData() && mediaLoadState != State.ERROR
|
||||
}
|
||||
|
||||
override fun onMediaLoadStateChange(@State state: Int) {
|
||||
mMediaLoadState = state
|
||||
mediaLoadState = state
|
||||
val activity = activity
|
||||
if (userVisibleHint && activity != null) {
|
||||
activity.supportInvalidateOptionsMenu()
|
||||
|
@ -94,11 +88,7 @@ class ImagePageFragment : SubsampleImageViewerFragment() {
|
|||
}
|
||||
|
||||
override fun getResultCreator(): CacheDownloadLoader.ResultCreator? {
|
||||
var creator = resultCreator
|
||||
if (creator != null) return creator
|
||||
creator = SizedResultCreator(context)
|
||||
resultCreator = creator
|
||||
return creator
|
||||
return sizedResultCreator
|
||||
}
|
||||
|
||||
private val media: ParcelableMedia
|
||||
|
@ -119,16 +109,16 @@ class ImagePageFragment : SubsampleImageViewerFragment() {
|
|||
|
||||
override fun onDownloadStart(total: Long, nonce: Long) {
|
||||
super.onDownloadStart(total, nonce)
|
||||
if (mediaDownloadEvent != null && mediaDownloadEvent!!.nonce == nonce) {
|
||||
mediaDownloadEvent!!.setOpenedTime(System.currentTimeMillis())
|
||||
mediaDownloadEvent!!.setSize(total)
|
||||
if (mediaDownloadEvent?.nonce == nonce) {
|
||||
mediaDownloadEvent?.setOpenedTime(System.currentTimeMillis())
|
||||
mediaDownloadEvent?.setSize(total)
|
||||
}
|
||||
}
|
||||
|
||||
override fun onDownloadFinished(nonce: Long) {
|
||||
super.onDownloadFinished(nonce)
|
||||
if (mediaDownloadEvent != null && mediaDownloadEvent!!.nonce == nonce) {
|
||||
mediaDownloadEvent!!.markEnd()
|
||||
if (mediaDownloadEvent?.nonce == nonce) {
|
||||
mediaDownloadEvent?.markEnd()
|
||||
HotMobiLogger.getInstance(context).log(accountKey, mediaDownloadEvent!!)
|
||||
mediaDownloadEvent = null
|
||||
}
|
||||
|
@ -181,35 +171,10 @@ class ImagePageFragment : SubsampleImageViewerFragment() {
|
|||
|
||||
@Throws(IOException::class)
|
||||
internal fun decodeBitmap(cr: ContentResolver, uri: Uri, o: BitmapFactory.Options): Bitmap? {
|
||||
var st: InputStream? = null
|
||||
try {
|
||||
st = cr.openInputStream(uri)
|
||||
return BitmapFactory.decodeStream(st, null, o)
|
||||
} finally {
|
||||
Utils.closeSilently(st)
|
||||
cr.openInputStream(uri).use {
|
||||
return BitmapFactory.decodeStream(it, null, o)
|
||||
}
|
||||
}
|
||||
|
||||
internal fun replaceTwitterMediaUri(downloadUri: Uri): Uri {
|
||||
// String uriString = downloadUri.toString();
|
||||
// if (TwitterMediaProvider.isSupported(uriString)) {
|
||||
// final String suffix = ".jpg";
|
||||
// int lastIndexOfJpegSuffix = uriString.lastIndexOf(suffix);
|
||||
// if (lastIndexOfJpegSuffix == -1) return downloadUri;
|
||||
// final int endOfSuffix = lastIndexOfJpegSuffix + suffix.length();
|
||||
// if (endOfSuffix == uriString.length()) {
|
||||
// return Uri.parse(uriString.substring(0, lastIndexOfJpegSuffix) + ".png");
|
||||
// } else {
|
||||
// // Seems :orig suffix won't work jpegs -> pngs
|
||||
// String sizeSuffix = uriString.substring(endOfSuffix);
|
||||
// if (":orig".equals(sizeSuffix)) {
|
||||
// sizeSuffix = ":large";
|
||||
// }
|
||||
// return Uri.parse(uriString.substring(0, lastIndexOfJpegSuffix) + ".png" +
|
||||
// sizeSuffix);
|
||||
// }
|
||||
// }
|
||||
return downloadUri
|
||||
}
|
||||
}
|
||||
}
|
|
@ -52,7 +52,7 @@
|
|||
<item name="android:windowTitleStyle">@style/Widget.TextView.WindowTitle.NoDisplay</item>
|
||||
</style>
|
||||
|
||||
<style name="Theme.Twidere.Viewer" parent="Theme.AppCompat">
|
||||
<style name="Theme.Twidere.Viewer" parent="Theme.Twidere.Dark">
|
||||
|
||||
<!-- Window attributes -->
|
||||
<item name="android:windowBackground">@color/background_color_window_viewer</item>
|
||||
|
@ -61,30 +61,13 @@
|
|||
<item name="actionBarStyle">@style/Widget.Twidere.Viewer.ActionBar</item>
|
||||
<item name="actionModeShareDrawable">@drawable/ic_action_share</item>
|
||||
|
||||
<!-- Widget styles -->
|
||||
<item name="android:listSeparatorTextViewStyle">@style/Widget.Dark.TextView.ListSeparator
|
||||
</item>
|
||||
|
||||
|
||||
<!-- Card UI styles -->
|
||||
<item name="cardActionButtonStyle">@style/Widget.CardActionButton</item>
|
||||
<item name="profileImageStyle">@style/Widget.ProfileImage</item>
|
||||
<item name="profileImageStyleLarge">@style/Widget.ProfileImage.Large</item>
|
||||
<item name="cardItemBackgroundColor">@color/background_color_card_item_dark</item>
|
||||
|
||||
<!-- Twidere specific styles -->
|
||||
<item name="menuIconColor">@color/action_icon_light</item>
|
||||
<item name="messageBubbleColor">@color/message_bubble_color_dark</item>
|
||||
<item name="quoteIndicatorBackgroundColor">@color/quote_indicator_background_dark</item>
|
||||
|
||||
<item name="colorToolbar">@color/background_color_action_bar_dark</item>
|
||||
<item name="isToolbarColored">false</item>
|
||||
|
||||
<item name="actionBarTheme">@null</item>
|
||||
<item name="preferenceTheme">@style/PreferenceThemeOverlay.v14.Material</item>
|
||||
|
||||
<item name="colorToolbar">#80000000</item>
|
||||
</style>
|
||||
|
||||
<style name="Theme.Nyan" parent="Theme.AppCompat.NoActionBar">
|
||||
<style name="Theme.Nyan" parent="Theme.Twidere.Dark">
|
||||
<item name="android:windowBackground">@color/nyan_background</item>
|
||||
<item name="colorPrimary">@color/nyan_background</item>
|
||||
</style>
|
||||
|
|
Loading…
Reference in New Issue