Skip to content

Commit

Permalink
Merge branch 'maintenance'
Browse files Browse the repository at this point in the history
  • Loading branch information
Tlaster committed Apr 21, 2020
2 parents b52e511 + fcf9b69 commit b022c55
Show file tree
Hide file tree
Showing 16 changed files with 266 additions and 156 deletions.
6 changes: 3 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ buildscript {
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.5.3'
classpath 'com.android.tools.build:gradle:3.6.3'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
Expand All @@ -17,8 +17,8 @@ allprojects {

ext {
projectGroupId = 'org.mariotaku.twidere'
projectVersionCode = 507
projectVersionName = '4.0.8'
projectVersionCode = 508
projectVersionName = '4.0.9'

globalCompileSdkVersion = 29
globalBuildToolsVersion = '29.0.2'
Expand Down
6 changes: 3 additions & 3 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Thu Oct 24 17:45:27 JST 2019
#Mon Apr 20 10:36:29 CEST 2020
distributionUrl=https\://services.gradle.org/distributions/gradle-6.1.1-all.zip
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.1.1-bin.zip
zipStoreBase=GRADLE_USER_HOME
2 changes: 1 addition & 1 deletion twidere/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ android {
exclude 'jsr305_annotations/**'
exclude 'error_prone/**'
exclude 'third_party/java_src/**'
exclude 'sdk-version.txt'
exclude 'sdk-version.txt'
exclude 'build-data.properties'
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import android.content.DialogInterface.OnClickListener;
import android.content.DialogInterface.OnMultiChoiceClickListener;
import android.content.DialogInterface.OnShowListener;
import android.net.Uri;
import android.os.Bundle;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
Expand Down Expand Up @@ -157,7 +158,7 @@ private void onPositiveButtonClicked(final int flags) {
final FragmentActivity a = getActivity();
final Bundle args = getArguments();
if (args == null) return;
final String path = args.getString(EXTRA_PATH);
final Uri path = args.getParcelable(EXTRA_PATH);
if (a instanceof Callback) {
((Callback) a).onPositiveButtonClicked(path, flags);
}
Expand All @@ -171,7 +172,7 @@ private void updatePositiveButton(final DialogInterface dialog) {
}

public interface Callback extends ISupportDialogFragmentCallback {
void onPositiveButtonClicked(String path, int flags);
void onPositiveButtonClicked(Uri path, int flags);
}

private static class Type {
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ public static String getApiBaseUrl(@NonNull String format, @Nullable final Strin
} else if (TextUtils.isEmpty(domain)) {
baseUrl = matcher.replaceAll("");
} else {
baseUrl = matcher.replaceAll("$1" + domain + "." + "$2");
baseUrl = matcher.replaceAll("$1" + domain + "$2" + "$3");
}
// In case someone set invalid base url
if (HttpUrl.parse(baseUrl) == null) {
Expand Down
29 changes: 23 additions & 6 deletions twidere/src/main/kotlin/androidx/core/os/LocaleHelperAccessor.kt
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,33 @@
package androidx.core.os

import android.annotation.SuppressLint
import android.os.Build
import java.util.*

@SuppressLint("RestrictedApi")
object LocaleHelperAccessor {
fun forLanguageTag(str: String): Locale {
if (str.contains("-")) {
val args = str.split("-").dropLastWhile { it.isEmpty() }.toTypedArray()
if (args.size > 2) {
return Locale(args[0], args[1], args[2])
} else if (args.size > 1) {
return Locale(args[0], args[1])
} else if (args.size == 1) {
return Locale(args[0])
}
} else if (str.contains("_")) {
val args = str.split("_").dropLastWhile { it.isEmpty() }.toTypedArray()
if (args.size > 2) {
return Locale(args[0], args[1], args[2])
} else if (args.size > 1) {
return Locale(args[0], args[1])
} else if (args.size == 1) {
return Locale(args[0])
}
} else {
return Locale(str)
}

fun forLanguageTag(str: String): Locale = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
Locale.forLanguageTag(str)
} else {
Locale(str)// TODO: Dose it work?
// TODO("VERSION.SDK_INT < LOLLIPOP")
throw IllegalArgumentException("Can not parse language tag: [$str]")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@ package org.mariotaku.twidere.activity

import android.app.Activity
import android.content.Intent
import android.net.Uri
import android.os.AsyncTask
import android.os.Build
import android.os.Bundle
import androidx.fragment.app.DialogFragment
import android.util.Log
import androidx.documentfile.provider.DocumentFile
import androidx.fragment.app.DialogFragment
import org.mariotaku.ktextension.dismissDialogFragment
import org.mariotaku.twidere.Constants.*
import org.mariotaku.twidere.R
Expand Down Expand Up @@ -39,10 +42,10 @@ class DataExportActivity : BaseActivity(), DataExportImportTypeSelectorDialogFra
REQUEST_PICK_DIRECTORY -> {
executeAfterFragmentResumed {
if (resultCode == RESULT_OK && data != null) {
val path = data.data?.path
val path = data.data
val df = DataExportImportTypeSelectorDialogFragment()
val args = Bundle()
args.putString(EXTRA_PATH, path)
args.putParcelable(EXTRA_PATH, path)
args.putString(EXTRA_TITLE, getString(R.string.export_settings_type_dialog_title))
df.arguments = args
df.show(supportFragmentManager, "select_export_type")
Expand All @@ -58,13 +61,18 @@ class DataExportActivity : BaseActivity(), DataExportImportTypeSelectorDialogFra
super.onActivityResult(requestCode, resultCode, data)
}

override fun onPositiveButtonClicked(path: String?, flags: Int) {
override fun onPositiveButtonClicked(path: Uri?, flags: Int) {
if (path == null || flags == 0) {
finish()
return
}
if (task == null || task!!.status != AsyncTask.Status.RUNNING) {
task = ExportSettingsTask(this, path, flags)
val folder = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
DocumentFile.fromTreeUri(this, path)
} else {
DocumentFile.fromFile(File(path.path))
}
task = ExportSettingsTask(this, folder, flags)
task!!.execute()
}
}
Expand All @@ -85,16 +93,18 @@ class DataExportActivity : BaseActivity(), DataExportImportTypeSelectorDialogFra

internal class ExportSettingsTask(
private val activity: DataExportActivity,
private val path: String?,
private val folder: DocumentFile?,
private val flags: Int
) : AsyncTask<Any, Any, Boolean>() {

override fun doInBackground(vararg params: Any): Boolean? {
if (path == null) return false
if (folder == null || !folder.isDirectory) return false
val sdf = SimpleDateFormat("yyyy-MM-dd_HH-mm-ss", Locale.US)
val fileName = String.format("Twidere_Settings_%s.zip", sdf.format(Date()))
val file = File(path, fileName)
file.delete()
val file = folder.findFile(fileName) ?: folder.createFile("application/zip", fileName)
?: return false
// val file = File(folder, fileName)
// file.delete()
try {
DataImportExportUtils.exportData(activity, file, flags)
return true
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
package org.mariotaku.twidere.activity

import android.content.Intent
import android.net.Uri
import android.os.AsyncTask
import android.os.Build
import android.os.Bundle
import androidx.fragment.app.DialogFragment
import android.util.Log
import androidx.documentfile.provider.DocumentFile
import androidx.fragment.app.DialogFragment
import org.mariotaku.ktextension.dismissDialogFragment
import org.mariotaku.twidere.R
import org.mariotaku.twidere.TwidereConstants.*
Expand Down Expand Up @@ -37,9 +40,14 @@ class DataImportActivity : BaseActivity(), DataExportImportTypeSelectorDialogFra
REQUEST_PICK_FILE -> {
resumeFragmentsRunnable = Runnable {
if (resultCode == RESULT_OK && data != null) {
val path = data.data?.path
val path = data.data!!
if (openImportTypeTask == null || openImportTypeTask!!.status != AsyncTask.Status.RUNNING) {
openImportTypeTask = OpenImportTypeTask(this@DataImportActivity, path)
val file = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
DocumentFile.fromSingleUri(this, path)
} else {
DocumentFile.fromFile(File(path.path))
}
openImportTypeTask = OpenImportTypeTask(this@DataImportActivity, file)
openImportTypeTask!!.execute()
}
} else {
Expand All @@ -62,13 +70,18 @@ class DataImportActivity : BaseActivity(), DataExportImportTypeSelectorDialogFra
}
}

override fun onPositiveButtonClicked(path: String?, flags: Int) {
override fun onPositiveButtonClicked(path: Uri?, flags: Int) {
if (path == null || flags == 0) {
finish()
return
}
if (importSettingsTask == null || importSettingsTask!!.status != AsyncTask.Status.RUNNING) {
importSettingsTask = ImportSettingsTask(this, path, flags)
val file = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
DocumentFile.fromSingleUri(this, path)
} else {
DocumentFile.fromFile(File(path.path))
}
importSettingsTask = ImportSettingsTask(this, file, flags)
importSettingsTask!!.execute()
}
}
Expand All @@ -89,13 +102,14 @@ class DataImportActivity : BaseActivity(), DataExportImportTypeSelectorDialogFra

internal class ImportSettingsTask(
private val activity: DataImportActivity,
private val path: String?,
private val file: DocumentFile?,
private val flags: Int
) : AsyncTask<Any, Any, Boolean>() {

override fun doInBackground(vararg params: Any): Boolean? {
if (path == null) return false
val file = File(path)
if (file == null) {
return false
}
if (!file.isFile) return false
try {
DataImportExportUtils.importData(activity, file, flags)
Expand Down Expand Up @@ -131,14 +145,15 @@ class DataImportActivity : BaseActivity(), DataExportImportTypeSelectorDialogFra

}

internal class OpenImportTypeTask(private val activity: DataImportActivity, private val path: String?) : AsyncTask<Any, Any, Int>() {
internal class OpenImportTypeTask(private val activity: DataImportActivity, private val file: DocumentFile?) : AsyncTask<Any, Any, Int>() {

override fun doInBackground(vararg params: Any): Int? {
if (path == null) return 0
val file = File(path)
if (file == null) {
return 0
}
if (!file.isFile) return 0
try {
return DataImportExportUtils.getImportedSettingsFlags(file)
return DataImportExportUtils.getImportedSettingsFlags(activity, file)
} catch (e: IOException) {
return 0
}
Expand All @@ -151,7 +166,7 @@ class DataImportActivity : BaseActivity(), DataExportImportTypeSelectorDialogFra
}
val df = DataExportImportTypeSelectorDialogFragment()
val args = Bundle()
args.putString(EXTRA_PATH, path)
args.putParcelable(EXTRA_PATH, file?.uri)
args.putString(EXTRA_TITLE, activity.getString(R.string.import_settings_type_dialog_title))
if (flags != null) {
args.putInt(EXTRA_FLAGS, flags)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ import android.net.Uri
import android.os.Build
import android.os.Bundle
import android.os.Environment.getExternalStorageDirectory
import android.widget.Toast
import androidx.core.app.ActivityCompat
import androidx.fragment.app.DialogFragment
import android.widget.Toast
import org.mariotaku.ktextension.Bundle
import org.mariotaku.ktextension.checkAllSelfPermissionsGranted
import org.mariotaku.ktextension.set
Expand All @@ -40,6 +40,8 @@ import android.Manifest.permission as AndroidPermissions

class FileSelectorActivity : BaseActivity(), FileSelectorDialogFragment.Callback {

private val PICKER_REQUEST_CODE: Int = 54837

override fun onCancelled(df: DialogFragment) {
if (!isFinishing) {
finish()
Expand All @@ -65,7 +67,7 @@ class FileSelectorActivity : BaseActivity(), FileSelectorDialogFragment.Callback
}

override fun onRequestPermissionsResult(requestCode: Int, permissions: Array<String>,
grantResults: IntArray) {
grantResults: IntArray) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults)
if (requestCode == REQUEST_REQUEST_PERMISSIONS) {
executeAfterFragmentResumed {
Expand Down Expand Up @@ -101,15 +103,44 @@ class FileSelectorActivity : BaseActivity(), FileSelectorDialogFragment.Callback
finish()
}

override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
super.onActivityResult(requestCode, resultCode, data)
if (requestCode == PICKER_REQUEST_CODE && resultCode == Activity.RESULT_OK && data != null) {
setResult(Activity.RESULT_OK, Intent().also { it.data = data.data })
finish()
} else {
if (!isFinishing) {
finish()
}
}
}

private fun showPickFileDialog() {
val initialDirectory = intent?.data?.path?.let(::File) ?: getExternalStorageDirectory() ?: File("/")
val f = FileSelectorDialogFragment()
f.arguments = Bundle {
this[EXTRA_ACTION] = intent.action
this[EXTRA_PATH] = initialDirectory.absolutePath
this[EXTRA_FILE_EXTENSIONS] = intent.getStringArrayExtra(EXTRA_FILE_EXTENSIONS)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
Intent().apply {
if (intent.action == INTENT_ACTION_PICK_FILE) {
action = Intent.ACTION_GET_CONTENT
type = "*/*"
} else if (intent.action == INTENT_ACTION_PICK_DIRECTORY) {
action = Intent.ACTION_OPEN_DOCUMENT_TREE
}
}.also {
startActivityForResult(
Intent.createChooser(it, getString(R.string.pick_file)),
PICKER_REQUEST_CODE
)
}
} else {
val initialDirectory = intent?.data?.path?.let(::File) ?: getExternalStorageDirectory()
?: File("/")
val f = FileSelectorDialogFragment()
f.arguments = Bundle {
this[EXTRA_ACTION] = intent.action
this[EXTRA_PATH] = initialDirectory.absolutePath
this[EXTRA_FILE_EXTENSIONS] = intent.getStringArrayExtra(EXTRA_FILE_EXTENSIONS)
}
f.show(supportFragmentManager, "select_file")
}
f.show(supportFragmentManager, "select_file")
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ val AccountExtras.official: Boolean
return false
}

val AccountDetails.hasDm: Boolean
get() = type in arrayOf(AccountType.FANFOU, AccountType.TWITTER)

fun <T> AccountDetails.newMicroBlogInstance(context: Context, cls: Class<T>): T {
return credentials.newMicroBlogInstance(context, type, cls)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ class SearchFragment : AbsToolbarTabPagesFragment(), RefreshScrollTopInterface,
customView.setOnClickListener {
val searchIntent = Intent(context, QuickSearchBarActivity::class.java).apply {
putExtra(EXTRA_QUERY, query)
putExtra(EXTRA_ACCOUNT_KEY, accountKey)
}
startActivityForResult(searchIntent, REQUEST_OPEN_SEARCH)
}
Expand Down
Loading

0 comments on commit b022c55

Please sign in to comment.