add changelog to updater

thanks, @LucasGGamerM!
This commit is contained in:
sk 2023-01-17 01:26:08 +01:00
parent eb1ab99262
commit 60edcfee1f
5 changed files with 78 additions and 53 deletions

View File

@ -61,6 +61,7 @@ public class GithubSelfUpdaterImpl extends GithubSelfUpdater{
info=new UpdateInfo();
info.version=prefs.getString("version", null);
info.size=prefs.getLong("apkSize", 0);
info.changelog=prefs.getString("changelog", null);
downloadID=prefs.getLong("downloadID", 0);
if(downloadID==0 || !getUpdateApkFile().exists()){
state=UpdateState.UPDATE_AVAILABLE;
@ -84,6 +85,7 @@ public class GithubSelfUpdaterImpl extends GithubSelfUpdater{
.remove("apkURL")
.remove("checkedByBuild")
.remove("downloadID")
.remove("changelog")
.apply();
}
}
@ -117,6 +119,7 @@ public class GithubSelfUpdaterImpl extends GithubSelfUpdater{
try(Response resp=call.execute()){
JsonObject obj=JsonParser.parseReader(resp.body().charStream()).getAsJsonObject();
String tag=obj.get("tag_name").getAsString();
String changelog=obj.get("body").getAsString();
Pattern pattern=Pattern.compile("v?(\\d+)\\.(\\d+)\\.(\\d+)\\+fork\\.(\\d+)");
Matcher matcher=pattern.matcher(tag);
if(!matcher.find()){
@ -151,12 +154,14 @@ public class GithubSelfUpdaterImpl extends GithubSelfUpdater{
UpdateInfo info=new UpdateInfo();
info.size=size;
info.version=version;
info.changelog=changelog;
this.info=info;
getPrefs().edit()
.putLong("apkSize", size)
.putString("version", version)
.putString("apkURL", url)
.putString("changelog", changelog)
.putInt("checkedByBuild", BuildConfig.VERSION_CODE)
.remove("downloadID")
.apply();

View File

@ -959,7 +959,7 @@ public class SettingsFragment extends MastodonToolbarFragment{
private class UpdateViewHolder extends BindableViewHolder<UpdateItem>{
private final TextView text;
private final TextView text, changelog;
private final Button button;
private final ImageButton cancelBtn;
private final ProgressBar progress;
@ -970,6 +970,7 @@ public class SettingsFragment extends MastodonToolbarFragment{
public UpdateViewHolder(){
super(getActivity(), R.layout.item_settings_update, list);
text=findViewById(R.id.text);
changelog=findViewById(R.id.changelog);
button=findViewById(R.id.button);
cancelBtn=findViewById(R.id.cancel_btn);
progress=findViewById(R.id.progress);
@ -1013,6 +1014,7 @@ public class SettingsFragment extends MastodonToolbarFragment{
progress.setVisibility(View.GONE);
progress.removeCallbacks(progressUpdater);
}
changelog.setText(info.changelog);
}
private void updateProgress(){

View File

@ -51,6 +51,7 @@ public abstract class GithubSelfUpdater{
public static class UpdateInfo{
public String version;
public String changelog;
public long size;
}
}

View File

@ -8,67 +8,83 @@
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="64dp"
android:gravity="center_vertical"
android:paddingStart="16dp"
android:background="@drawable/bg_settings_update"
android:orientation="horizontal">
android:orientation="vertical"
android:background="@drawable/bg_settings_update">
<TextView
android:id="@+id/text"
android:layout_width="0dp"
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_marginEnd="4dp"
android:layout_marginTop="16dp"
android:layout_marginBottom="16dp"
android:textAppearance="@style/m3_body_medium"
tools:text="@string/sk_update_available"/>
android:minHeight="64dp"
android:gravity="center_vertical"
android:orientation="horizontal">
<FrameLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView
android:id="@+id/text"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_marginVertical="16dp"
android:layout_marginEnd="16dp"
android:layout_marginStart="8dp"
android:textAppearance="@style/m3_body_medium"
tools:text="@string/sk_update_available"/>
<Button
android:id="@+id/button"
<FrameLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical|end"
android:background="?android:selectableItemBackground"
android:textColor="?android:textColorPrimary"
android:textAllCaps="true"
android:textSize="14sp"
android:paddingLeft="16dp"
android:paddingRight="16dp"
android:stateListAnimator="@null"
tools:text="@string/install_update"/>
android:layout_marginEnd="16dp">
<ImageButton
android:id="@+id/cancel_btn"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_gravity="end|center_vertical"
android:layout_marginEnd="16dp"
android:background="@drawable/bg_update_download_progress"
android:tint="?colorSearchHint"
android:contentDescription="@string/cancel"
android:visibility="gone"
android:src="@drawable/ic_fluent_dismiss_16_filled"/>
<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical|end"
android:stateListAnimator="@null"
tools:text="@string/install_update"/>
<ProgressBar
android:id="@+id/progress"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_gravity="end|center_vertical"
android:layout_marginEnd="16dp"
android:progressDrawable="@drawable/update_progress"
android:max="1000"
android:padding="0dp"
android:visibility="gone"
android:indeterminateOnly="false"
android:indeterminate="false"/>
<ImageButton
android:id="@+id/cancel_btn"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_gravity="end|center_vertical"
android:background="@drawable/bg_update_download_progress"
android:tint="?colorSearchHint"
android:contentDescription="@string/cancel"
android:visibility="gone"
android:src="@drawable/ic_fluent_dismiss_16_filled"/>
</FrameLayout>
<ProgressBar
android:id="@+id/progress"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_gravity="end|center_vertical"
android:progressDrawable="@drawable/update_progress"
android:max="1000"
android:padding="0dp"
android:visibility="gone"
android:indeterminateOnly="false"
android:indeterminate="false"/>
</FrameLayout>
</LinearLayout>
<TextView
android:id="@+id/changelog_header"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAppearance="@style/m3_title_medium"
android:paddingHorizontal="16dp"
android:text="@string/sk_changelog" />
<TextView
android:id="@+id/changelog"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAppearance="@style/m3_body_medium"
android:paddingHorizontal="16dp"
android:paddingTop="8dp"
android:paddingBottom="16dp"/>
</LinearLayout>

View File

@ -148,4 +148,5 @@
<string name="sk_remove_follower_confirm">Remove %s as a follower by blocking and immediately unblocking them?</string>
<string name="sk_do_remove_follower">Remove</string>
<string name="sk_remove_follower_success">Successfully removed follower</string>
<string name="sk_changelog">Changelog</string>
</resources>