Merge remote-tracking branch 'origin/feature/show_changelog_button' into feature/show_changelog_button

This commit is contained in:
LucasGGamerM 2022-12-25 14:18:59 -03:00
commit b060894a6c
4 changed files with 49 additions and 0 deletions

View File

@ -40,6 +40,7 @@ import okhttp3.Response;
public class GithubSelfUpdaterImpl extends GithubSelfUpdater{
private static final long CHECK_PERIOD=6*3600*1000L;
private static final String TAG="GithubSelfUpdater";
private static String changelog;
private UpdateState state=UpdateState.NO_UPDATE;
private UpdateInfo info;
@ -109,6 +110,11 @@ public class GithubSelfUpdaterImpl extends GithubSelfUpdater{
MastodonAPIController.runInBackground(this::actuallyCheckForUpdates);
}
@Override
public void getChangelog(){
MastodonAPIController.runInBackground(this::actuallyGetChangelog);
}
private void actuallyCheckForUpdates(){
Request req=new Request.Builder()
.url("https://api.github.com/repos/LucasGGamerM/moshidon/releases/latest")
@ -175,6 +181,35 @@ public class GithubSelfUpdaterImpl extends GithubSelfUpdater{
}
}
public void actuallyGetChangelog(){
String changelog = null;
Request req=new Request.Builder()
.url("https://api.github.com/repos/LucasGGamerM/moshidon/releases/latest")
.build();
Call call=MastodonAPIController.getHttpClient().newCall(req);
try(Response resp=call.execute()){
JsonObject obj=JsonParser.parseReader(resp.body().charStream()).getAsJsonObject();
changelog=obj.get("body").getAsString();
if(changelog == null){
Log.w(TAG, "No changelog available");
return;
}
}catch(Exception x){
Log.w(TAG, "getChangelog: ", x);
}finally{
// setState(changelog==null ? UpdateState.NO_UPDATE : UpdateState.UPDATE_AVAILABLE);
setChangelog(changelog);
}
}
private void setChangelog(String changelog){
this.changelog = changelog;
}
public String getChangelogText(){
return changelog;
}
private void setState(UpdateState state){
this.state=state;
E.post(new SelfUpdateStateChangedEvent(state));

View File

@ -3,6 +3,7 @@ package org.joinmastodon.android.fragments;
import android.animation.ObjectAnimator;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.Canvas;
@ -49,6 +50,7 @@ import org.joinmastodon.android.ui.M3AlertDialogBuilder;
import org.joinmastodon.android.ui.OutlineProviders;
import org.joinmastodon.android.ui.utils.UiUtils;
import org.joinmastodon.android.updater.GithubSelfUpdater;
import org.w3c.dom.Text;
import java.util.ArrayList;
import java.util.function.Consumer;
@ -185,6 +187,9 @@ public class SettingsFragment extends MastodonToolbarFragment{
checkForUpdateItem = new TextItem(R.string.sk_check_for_update, GithubSelfUpdater.getInstance()::checkForUpdates);
items.add(checkForUpdateItem);
}
// TODO fix this up tomorrow, by probably just making another method for chacking and displaying the new changelog
items.add(new TextItem(R.string.sk_get_changelog, this::onGetChangelogClick));
items.add(new TextItem(R.string.sk_settings_contribute, ()->UiUtils.launchWebBrowser(getActivity(), "https://github.com/LucasGGamerM/moshidon")));
items.add(new TextItem(R.string.settings_clear_cache, this::clearImageCache));
items.add(new TextItem(R.string.sk_clear_recent_languages, ()->UiUtils.showConfirmationAlert(getActivity(), R.string.sk_clear_recent_languages, R.string.sk_confirm_clear_recent_languages, R.string.clear, ()->{
@ -262,6 +267,12 @@ public class SettingsFragment extends MastodonToolbarFragment{
E.unregister(this);
}
private void onGetChangelogClick(){
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(getContext());
alertDialogBuilder.setTitle("Something TODO remove this");
alertDialogBuilder.setMessage(GithubSelfUpdater.getInstance().getChangelog());
}
private void onThemePreferenceClick(GlobalUserPreferences.ThemePreference theme){
GlobalUserPreferences.theme=theme;
GlobalUserPreferences.save();

View File

@ -39,6 +39,8 @@ public abstract class GithubSelfUpdater{
public abstract void cancelDownload();
public abstract String getChangelog();
public abstract void handleIntentFromInstaller(Intent intent, Activity activity);
public enum UpdateState{

View File

@ -89,4 +89,5 @@
<string name="sk_reblog_with_visibility">Reblog with visibility</string>
<string name="sk_quote_post">Post about this</string>
<string name="sk_hashtags_you_follow">Hashtags you follow</string>
<string name="sk_get_changelog">Get changelog</string>
</resources>