Skip to content

Commit

Permalink
fix: SDK 29 fixes, 1.0.2.0 release
Browse files Browse the repository at this point in the history
  • Loading branch information
feelfreelinux committed Jul 22, 2020
1 parent 4cd8523 commit 2345ed2
Show file tree
Hide file tree
Showing 10 changed files with 126 additions and 104 deletions.
14 changes: 7 additions & 7 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -98,15 +98,15 @@ dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$versions.kotlin"

// Support library
implementation 'androidx.appcompat:appcompat:1.2.0-alpha03'
implementation 'androidx.recyclerview:recyclerview:1.2.0-alpha01'
implementation 'androidx.appcompat:appcompat:1.3.0-alpha01'
implementation 'androidx.recyclerview:recyclerview:1.2.0-alpha04'
implementation "android.arch.work:work-runtime:1.0.1"
implementation 'androidx.exifinterface:exifinterface:1.1.0'
implementation 'androidx.exifinterface:exifinterface:1.2.0'
implementation 'androidx.cardview:cardview:1.0.0'
implementation 'androidx.preference:preference:1.1.0-alpha02'
implementation 'androidx.preference:preference:1.1.1'
implementation 'androidx.legacy:legacy-preference-v14:1.0.0'
implementation 'com.google.android.material:material:1.2.0-alpha05'
implementation 'com.takisoft.preferencex:preferencex:1.0.0-alpha2'
implementation 'com.google.android.material:material:1.3.0-alpha01'
implementation 'com.takisoft.preferencex:preferencex:1.1.0'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation 'androidx.browser:browser:1.2.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
Expand All @@ -117,7 +117,7 @@ dependencies {
implementation 'com.google.android.exoplayer:extension-okhttp:2.9.6'
implementation 'com.davemorrissey.labs:subsampling-scale-image-view:3.10.0'
implementation 'com.google.code.gson:gson:2.8.5'
implementation 'androidx.core:core-ktx:1.3.0-alpha02'
implementation 'androidx.core:core-ktx:1.5.0-alpha01'

// Utils
implementation 'com.bugsnag:bugsnag-android:4.5.0'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ import retrofit2.http.Headers

interface PatronsRetrofitApi {
@Headers("@: $REMOVE_USERKEY_HEADER")
@GET("https://patrons.grzywok.eu/api/patrons")
@GET("https://raw.githubusercontent.com/alufers/owm-patrons/master/patrons.json")
fun getPatrons(): Single<PatronsResponse>
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import android.os.Environment
import android.os.Handler
import android.os.Looper
import android.provider.MediaStore
import android.util.Base64
import android.util.Log
import android.view.Menu
import android.view.MenuItem
import android.webkit.MimeTypeMap
Expand Down Expand Up @@ -45,7 +45,6 @@ import okhttp3.Request
import okio.Okio
import java.io.File
import java.net.URL
import java.nio.charset.Charset
import javax.inject.Inject

class EmbedViewActivity : BaseActivity(), EmbedView {
Expand Down Expand Up @@ -96,21 +95,6 @@ class EmbedViewActivity : BaseActivity(), EmbedView {
videoView.isFocusable = false
}

private fun decodeCoubUrl(input: String): String? {
val source = StringBuilder(input)
for (a in 0 until source.length) {
val c = source[a]
val lower = Character.toLowerCase(c)
source.setCharAt(a, if (c == lower) Character.toUpperCase(c) else lower)
}
return try {
String(Base64.decode(source.toString(), Base64.DEFAULT), Charset.forName("UTF-8"))
} catch (ignore: Exception) {
null
}

}

override fun checkEmbedSettings() {
if (settingsPreferencesApi.enableEmbedPlayer) {
openBrowser(extraUrl)
Expand Down Expand Up @@ -223,40 +207,52 @@ class EmbedViewActivity : BaseActivity(), EmbedView {
private fun saveFile() {
Single.create<String> {
val url = presenter.mp4Url
val path = File(
Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES),
PhotoViewActions.SAVED_FOLDER
)

val file = File(path, url.substringAfterLast("/"))
val request = Request.Builder()
.url(url)
.build()
val result = OkHttpClient().newCall(request).execute()
if (result.isSuccessful) {
val sink = Okio.buffer(Okio.sink(file))
sink.writeAll(result.body()!!.source())
sink.close()
} else {
it.onError(Exception())
val relativeLocation = Environment.DIRECTORY_MOVIES
var fileUrl = url.substringAfterLast("/")
if (fileUrl.contains("?")) {
fileUrl = fileUrl.substringBefore("?")
}
it.onSuccess(path.path)
val contentValues = ContentValues()
contentValues.put(MediaStore.MediaColumns.DISPLAY_NAME, fileUrl)
contentValues.put(MediaStore.MediaColumns.MIME_TYPE, "video/mp4")
contentValues.put(MediaStore.Images.Media.DATE_TAKEN, System.currentTimeMillis())
contentValues.put(MediaStore.MediaColumns.RELATIVE_PATH, relativeLocation + "/" + PhotoViewActions.SAVED_FOLDER)
val contentUri = MediaStore.Video.Media.EXTERNAL_CONTENT_URI;
val uri = contentResolver.insert(contentUri, contentValues);
uri?.let {
uri ->
val stream = contentResolver.openOutputStream(uri)
val request = Request.Builder()
.url(url)
.build()
val result = OkHttpClient().newCall(request).execute()
if (result.isSuccessful) {
val sink = Okio.buffer(Okio.sink(stream))
sink.writeAll(result.body()!!.source())
sink.close()
} else {
it.onError(Exception())
}
}
it.onSuccess(relativeLocation + "/" + PhotoViewActions.SAVED_FOLDER)


}.subscribeOn(WykopSchedulers().backgroundThread())
.observeOn(WykopSchedulers().mainThread())
.subscribe({
val values = ContentValues()

values.put(MediaStore.Images.Media.DATE_TAKEN, System.currentTimeMillis())

values.put(MediaStore.Images.Media.MIME_TYPE, getMimeType(it))


values.put(MediaStore.MediaColumns.DATA, it)
// val values = ContentValues()
//
// values.put(MediaStore.Images.Media.DATE_TAKEN, System.currentTimeMillis())
//
// values.put(MediaStore.Images.Media.MIME_TYPE, getMimeType(it))
//
//
// values.put(MediaStore.MediaColumns.DATA, it)
Toast.makeText(this, "Zapisano plik", Toast.LENGTH_SHORT).show()
contentResolver.insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values)
// contentResolver.insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values)
}, {
throw it
Toast.makeText(this, "Błąd podczas zapisu pliku", Toast.LENGTH_SHORT).show()
})
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import android.graphics.drawable.Drawable
import android.os.Environment
import android.provider.MediaStore
import android.provider.MediaStore.Images
import android.util.Log
import android.webkit.MimeTypeMap
import android.widget.Toast
import androidx.core.app.ActivityCompat
Expand All @@ -21,6 +22,7 @@ import io.reactivex.Single
import io.reactivex.SingleOnSubscribe
import java.io.File


interface PhotoViewCallbacks {
fun shareImage(url: String)
fun getDrawable(): Drawable?
Expand All @@ -43,19 +45,24 @@ class PhotoViewActions(val context: Context) : PhotoViewCallbacks {

Single.create(SingleOnSubscribe<File> {
val file = Glide.with(context).downloadOnly().load(url).submit().get()
val newFile = File(
Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES),
"$SAVED_FOLDER/$SHARED_FOLDER/" + url.substringAfterLast("/")
)
file.copyTo(newFile, true)
var fileUrl = url.substringAfterLast("/")
if (fileUrl.contains("?")) {
fileUrl = fileUrl.substringBefore("?")
}
val newFile = File(file.path.substringBeforeLast("/") + "/" + fileUrl)
file.renameTo(newFile)


it.onSuccess(newFile)
}).subscribeOn(WykopSchedulers().backgroundThread()).observeOn(WykopSchedulers().mainThread()).subscribe { file: File ->
addImageToGallery(file.path, context)

val url = FileProvider.getUriForFile(context, context.applicationContext.packageName + ".fileprovider", file)
val share = Intent(Intent.ACTION_SEND)
share.type = getMimeType(url.path!!)
share.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
share.putExtra(Intent.EXTRA_STREAM, url)
share.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

photoView.startActivityForResult(Intent.createChooser(share, "Udostępnij obrazek"), PhotoViewActivity.SHARE_REQUEST_CODE)
}
}
Expand All @@ -72,14 +79,29 @@ class PhotoViewActions(val context: Context) : PhotoViewCallbacks {
return
}
Completable.fromAction {
val file = Glide.with(context).downloadOnly().load(url).submit().get()
var path = File(
Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES),
SAVED_FOLDER
)
path = File(path, photoView.url.substringAfterLast('/'))
file.copyTo(path, true)
addImageToGallery(path.path, context)

val relativeLocation = Environment.DIRECTORY_PICTURES
var fileUrl = url.substringAfterLast("/")
if (fileUrl.contains("?")) {
fileUrl = fileUrl.substringBefore("?")
}
val contentValues = ContentValues()
contentValues.put(MediaStore.MediaColumns.DISPLAY_NAME, fileUrl)
contentValues.put(MediaStore.MediaColumns.MIME_TYPE, getMimeType(url))
contentValues.put(MediaStore.Images.Media.DATE_TAKEN, System.currentTimeMillis())
contentValues.put(MediaStore.MediaColumns.RELATIVE_PATH, relativeLocation + "/" + PhotoViewActions.SAVED_FOLDER)
val contentUri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI;
val uri = context.contentResolver.insert(contentUri, contentValues)
uri?.let {
uri ->
val stream = context.contentResolver.openOutputStream(uri)

val file = Glide.with(context).downloadOnly().load(url).submit().get()

file.inputStream().copyTo(stream!!)

}

}.subscribeOn(WykopSchedulers().backgroundThread())
.observeOn(WykopSchedulers().mainThread()).subscribe({
showToastMessage("Zapisano plik")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,34 +30,34 @@ class SettingsAppearance : PreferenceFragmentCompat(), SharedPreferences.OnShare

override fun onCreatePreferencesFix(savedInstanceState: Bundle?, rootKey: String?) {
addPreferencesFromResource(R.xml.app_preferences_appearance)
findPreference<Preference>("useAmoledTheme").isEnabled = settingsApi.useDarkTheme
findPreference<Preference>("cutImageProportion").isEnabled = settingsApi.cutImages
findPreference<Preference>("linkImagePosition").isEnabled = !settingsApi.linkSimpleList && settingsApi.linkShowImage
findPreference<Preference>("linkShowAuthor").isEnabled = !settingsApi.linkSimpleList
findPreference<Preference>("useAmoledTheme")?.isEnabled = settingsApi.useDarkTheme
findPreference<Preference>("cutImageProportion")?.isEnabled = settingsApi.cutImages
findPreference<Preference>("linkImagePosition")?.isEnabled = !settingsApi.linkSimpleList && settingsApi.linkShowImage
findPreference<Preference>("linkShowAuthor")?.isEnabled = !settingsApi.linkSimpleList

(findPreference("hotEntriesScreen") as ListPreference).apply {
(findPreference("hotEntriesScreen") as ListPreference?)!!.apply {
summary = entry
}

(findPreference("fontSize") as ListPreference).apply {
(findPreference("fontSize") as ListPreference?)!!.apply {
summary = entry
}

(findPreference("defaultScreen") as ListPreference).apply {
(findPreference("defaultScreen") as ListPreference?)!!.apply {
summary = entry
}

(findPreference("linkImagePosition") as ListPreference).apply {
(findPreference("linkImagePosition") as ListPreference?)!!.apply {
summary = entry
}
}

override fun onSharedPreferenceChanged(sharedPrefs: SharedPreferences, key: String) {
val pref = findPreference<Preference>(key)
findPreference<Preference>("useAmoledTheme").isEnabled = settingsApi.useDarkTheme
findPreference<Preference>("cutImageProportion").isEnabled = settingsApi.cutImages
findPreference<Preference>("linkShowAuthor").isEnabled = !settingsApi.linkSimpleList
findPreference<Preference>("linkImagePosition").isEnabled = !settingsApi.linkSimpleList
findPreference<Preference>("useAmoledTheme")?.isEnabled = settingsApi.useDarkTheme
findPreference<Preference>("cutImageProportion")?.isEnabled = settingsApi.cutImages
findPreference<Preference>("linkShowAuthor")?.isEnabled = !settingsApi.linkSimpleList
findPreference<Preference>("linkImagePosition")?.isEnabled = !settingsApi.linkSimpleList

if (pref is ListPreference) {
pref.setSummary(pref.entry)
Expand Down
Loading

0 comments on commit 2345ed2

Please sign in to comment.