Skip to content

Commit

Permalink
Merge pull request #250 from shibafu528/topic/249-auto-fix-font-size
Browse files Browse the repository at this point in the history
起動時に1回だけTLと投稿画面の文字サイズを設定値の80%に縮める
  • Loading branch information
shibafu528 committed Jul 8, 2019
2 parents 2088988 + 5185b62 commit f8d12e7
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,11 @@ class BackupActivity : ActionBarYukariBase(), SimpleAlertDialogFragment.OnDialog
11 -> {
val records: Map<String, Any?> = Gson().fromJson(readFile("prefs.json"), object : TypeToken<Map<String, Any?>>() {}.type)
val spEdit = PreferenceManager.getDefaultSharedPreferences(applicationContext).edit()

// マイグレーションフラグを削除する (インポートしたデータがそれらのマイグレーションを実施済であれば、それも入っているはずなので)
spEdit.remove("pref_font_timeline__migrate_3_0_0")
spEdit.remove("pref_font_input__migrate_3_0_0")

records.forEach {
var value = it.value
if (value is Double) {
Expand Down
31 changes: 31 additions & 0 deletions Yukari/src/main/java/shibafu/yukari/core/YukariApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import android.app.NotificationChannelGroup;
import android.app.NotificationManager;
import android.content.Context;
import android.content.SharedPreferences;
import android.media.AudioAttributes;
import android.media.AudioManager;
import android.net.Uri;
Expand Down Expand Up @@ -80,6 +81,8 @@ public void onCreate() {
createAllAccountNotificationChannels(nm);
}

migratePreference();

if (LeakCanary.isInAnalyzerProcess(this)) {
return;
}
Expand Down Expand Up @@ -142,4 +145,32 @@ private void createAllAccountNotificationChannels(@NonNull NotificationManager n

nm.createNotificationChannels(channels);
}

/**
* マイグレーションの必要な設定を検出し、修正します。
*/
private void migratePreference() {
SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(this);

// ver 3.0.0
{
SharedPreferences.Editor edit = sp.edit();

// 文字サイズの設定
if (sp.contains("pref_font_timeline") && !sp.getBoolean("pref_font_timeline__migrate_3_0_0", false)) {
int size = (int) (Integer.parseInt(sp.getString("pref_font_timeline", "14")) * 0.8);
edit.putString("pref_font_timeline", String.valueOf(size));
}
edit.putBoolean("pref_font_timeline__migrate_3_0_0", true);

// 入力文字サイズの設定
if (sp.contains("pref_font_input") && !sp.getBoolean("pref_font_input__migrate_3_0_0", false)) {
int size = (int) (Integer.parseInt(sp.getString("pref_font_input", "18")) * 0.8);
edit.putString("pref_font_input", String.valueOf(size));
}
edit.putBoolean("pref_font_input__migrate_3_0_0", true);

edit.apply();
}
}
}

0 comments on commit f8d12e7

Please sign in to comment.