diff --git a/app/src/main/assets/pl-changelog.html b/app/src/main/assets/pl-changelog.html index d44c0246..566092d5 100644 --- a/app/src/main/assets/pl-changelog.html +++ b/app/src/main/assets/pl-changelog.html @@ -1,53 +1,37 @@ - - - - - - - -

Wersja 4.0, 2019-jeszcze-nie-wiem-kiedy

+

Wersja 4.0-beta.1, 2019-12-31

- - - - \ No newline at end of file +
+
+
+Uwaga. Ponieważ to wersja beta, niektóre funkcje mogą nie działać prawidłowo.
+Staramy się usuwać takie przypadki, jednak na chwilę obecną mogą występować błędy w: + +
+
+
+
+Okazja ograniczona czasowo: Poczuj prawdziwą zimę, włączając w Ustawieniach widok padającego śniegu! +
+
+
+Dzięki za korzystanie ze Szkolnego!
+© Kuba Szczodrzyński, Kacper Ziubryniewicz 2019 diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/MainActivity.kt b/app/src/main/java/pl/szczodrzynski/edziennik/MainActivity.kt index afe23c3c..915d940a 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/MainActivity.kt +++ b/app/src/main/java/pl/szczodrzynski/edziennik/MainActivity.kt @@ -9,7 +9,10 @@ import android.content.IntentFilter import android.content.pm.PackageManager import android.graphics.BitmapFactory import android.graphics.drawable.BitmapDrawable -import android.os.* +import android.os.AsyncTask +import android.os.Build +import android.os.Bundle +import android.os.Environment import android.provider.Settings import android.util.Log import android.view.Gravity @@ -36,13 +39,11 @@ import org.greenrobot.eventbus.EventBus import org.greenrobot.eventbus.Subscribe import org.greenrobot.eventbus.ThreadMode import pl.droidsonroids.gif.GifDrawable -import pl.szczodrzynski.edziennik.App.APP_URL import pl.szczodrzynski.edziennik.data.api.events.* import pl.szczodrzynski.edziennik.data.api.szkolny.interceptor.Signing import pl.szczodrzynski.edziennik.data.api.task.EdziennikTask import pl.szczodrzynski.edziennik.data.db.modules.metadata.Metadata.* import pl.szczodrzynski.edziennik.databinding.ActivitySzkolnyBinding -import pl.szczodrzynski.edziennik.network.ServerRequest import pl.szczodrzynski.edziennik.sync.AppManagerDetectedEvent import pl.szczodrzynski.edziennik.sync.SyncWorker import pl.szczodrzynski.edziennik.ui.dialogs.changelog.ChangelogDialog @@ -426,16 +427,7 @@ class MainActivity : AppCompatActivity() { // WHAT'S NEW DIALOG if (app.config.appVersion < BuildConfig.VERSION_CODE) { - ServerRequest(app, app.requestScheme + APP_URL + "main.php?just_updated", "MainActivity/JU") - .run { e, result -> - Handler(Looper.getMainLooper()).post { - try { - ChangelogDialog().show(supportFragmentManager, "whats_new") - } catch (e2: Exception) { - e2.printStackTrace() - } - } - } + ChangelogDialog(this) if (app.config.appVersion < 170) { //Intent intent = new Intent(this, ChangelogIntroActivity.class); //startActivity(intent); diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/ui/dialogs/changelog/ChangelogDialog.java b/app/src/main/java/pl/szczodrzynski/edziennik/ui/dialogs/changelog/ChangelogDialog.java deleted file mode 100644 index dfae3081..00000000 --- a/app/src/main/java/pl/szczodrzynski/edziennik/ui/dialogs/changelog/ChangelogDialog.java +++ /dev/null @@ -1,92 +0,0 @@ -package pl.szczodrzynski.edziennik.ui.dialogs.changelog; - -import android.app.Dialog; -import android.os.Bundle; -import androidx.annotation.NonNull; -import androidx.fragment.app.DialogFragment; -import android.view.InflateException; -import android.view.LayoutInflater; -import android.view.View; -import android.webkit.WebView; -import android.widget.Toast; - -import com.afollestad.materialdialogs.MaterialDialog; -import com.afollestad.materialdialogs.Theme; - -import java.io.BufferedReader; -import java.io.InputStream; -import java.io.InputStreamReader; - -import pl.szczodrzynski.edziennik.App; -import pl.szczodrzynski.edziennik.R; -import pl.szczodrzynski.edziennik.utils.Themes; - -import static pl.szczodrzynski.edziennik.utils.Utils.hexFromColorInt; -import static pl.szczodrzynski.navlib.UtilsKt.getColorFromAttr; - -public class ChangelogDialog extends DialogFragment { - - private String charsetName = "UTF-8"; - - private int getColor(int resId) - { - return getContext().getResources().getColor(resId); - } - - @NonNull - @Override - public Dialog onCreateDialog(Bundle savedInstanceState) { - assert getContext() != null; - assert getActivity() != null; - App app = (App)getContext().getApplicationContext(); - final View customView; - try { - customView = LayoutInflater.from(getActivity()).inflate(R.layout.dialog_changelog, null); - } catch (InflateException e) { - Toast.makeText(getContext(), "This device does not support WebViews.", Toast.LENGTH_SHORT).show(); - return null; - } - boolean darkTheme = Themes.INSTANCE.isDark(); - - MaterialDialog dialog = - new MaterialDialog.Builder(getActivity()) - .theme(darkTheme ? Theme.DARK : Theme.LIGHT) - .title(R.string.whats_new) - .customView(customView, true) - .positiveText(android.R.string.ok) - .build(); - - WebView webView = customView.findViewById(R.id.webview); - try { - - // Load from changelog.html in the assets folder - StringBuilder buf = new StringBuilder(); - InputStream json = getActivity().getAssets().open(getContext().getString(R.string.prefix)+"-changelog.html"); - BufferedReader in = new BufferedReader(new InputStreamReader(json, charsetName)); - String str; - while ((str = in.readLine()) != null) { - buf.append(str); - } - in.close(); - - // Inject color values for WebView body background and links - webView.loadDataWithBaseURL(null, - buf.toString() - .replace("{bg-color}", hexFromColorInt(darkTheme ? 0x424242 : 0xffffff)) - .replace("{text-color}", colorToHex(getColorFromAttr(getContext(), android.R.attr.textColorPrimary))) - .replace("{secondary-color}", colorToHex(getColorFromAttr(getContext(), android.R.attr.textColorSecondary))) - .replace("{link-color}", colorToHex(getColorFromAttr(getContext(), R.attr.colorAccent))) - .replace("{link-color-active}", colorToHex(getColorFromAttr(getContext(), R.attr.colorPrimaryDark))), - "text/html", - charsetName, null); - } catch (Throwable e) { - webView.loadData( - "

Unable to load

" + e.getLocalizedMessage() + "

", "text/html", charsetName); - } - return dialog; - } - - private String colorToHex(int color) { - return Integer.toHexString(color).substring(2); - } -} diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/ui/dialogs/changelog/ChangelogDialog.kt b/app/src/main/java/pl/szczodrzynski/edziennik/ui/dialogs/changelog/ChangelogDialog.kt new file mode 100644 index 00000000..98991065 --- /dev/null +++ b/app/src/main/java/pl/szczodrzynski/edziennik/ui/dialogs/changelog/ChangelogDialog.kt @@ -0,0 +1,64 @@ +/* + * Copyright (c) Kuba Szczodrzyński 2019-12-30. + */ + +package pl.szczodrzynski.edziennik.ui.dialogs.changelog + +import android.text.Html +import android.widget.ScrollView +import android.widget.TextView +import androidx.appcompat.app.AlertDialog +import androidx.appcompat.app.AppCompatActivity +import com.google.android.material.dialog.MaterialAlertDialogBuilder +import kotlinx.coroutines.CoroutineScope +import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.Job +import pl.szczodrzynski.edziennik.App +import pl.szczodrzynski.edziennik.R +import pl.szczodrzynski.edziennik.dp +import kotlin.coroutines.CoroutineContext + +class ChangelogDialog( + val activity: AppCompatActivity, + val onShowListener: ((tag: String) -> Unit)? = null, + val onDismissListener: ((tag: String) -> Unit)? = null +) : CoroutineScope { + companion object { + private const val TAG = "ChangelogDialog" + } + + private lateinit var app: App + private lateinit var dialog: AlertDialog + + private val job = Job() + override val coroutineContext: CoroutineContext + get() = job + Dispatchers.Main + + init { run { + if (activity.isFinishing) + return@run + onShowListener?.invoke(TAG) + app = activity.applicationContext as App + val textView = TextView(activity) + textView.setPadding(24.dp, 24.dp, 24.dp, 0) + + val text = app.assets.open("pl-changelog.html").bufferedReader().use { + it.readText() + } + textView.text = Html.fromHtml(text) + + val scrollView = ScrollView(activity) + scrollView.addView(textView) + + dialog = MaterialAlertDialogBuilder(activity) + .setTitle(R.string.whats_new) + .setView(scrollView) + .setPositiveButton(R.string.close) { dialog, _ -> + dialog.dismiss() + } + .setOnDismissListener { + onDismissListener?.invoke(TAG) + } + .show() + }} +} \ No newline at end of file diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/settings/SettingsNewFragment.java b/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/settings/SettingsNewFragment.java index be2b5db3..fd7daa71 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/settings/SettingsNewFragment.java +++ b/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/settings/SettingsNewFragment.java @@ -1242,7 +1242,7 @@ public class SettingsNewFragment extends MaterialAboutFragment { .icon(CommunityMaterial.Icon2.cmd_radar) .color(IconicsColor.colorInt(primaryTextOnPrimaryBg)) .size(IconicsSize.dp(iconSizeDp))) - .setOnClickAction(() -> new ChangelogDialog().show(getActivity().getSupportFragmentManager(), "whats_new")) + .setOnClickAction(() -> new ChangelogDialog(activity, null, null)) .build()); items.add(new MaterialAboutActionItem.Builder()