Skip to content

Commit

Permalink
Remove Bug SongViewFragment Toast in Handlerthread
Browse files Browse the repository at this point in the history
  • Loading branch information
AndInTheClouds committed Nov 30, 2022
1 parent 5985f7e commit 2251461
Showing 1 changed file with 20 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import android.os.CountDownTimer;
import android.os.Handler;
import android.os.HandlerThread;
import android.os.Looper;
import android.os.Message;
import android.text.InputType;
import android.text.Layout;
Expand Down Expand Up @@ -471,14 +472,13 @@ public void handleMessage(Message msg) {
super.handleMessage(msg);
Boolean successfullySavedLog = (Boolean) msg.obj;
if(successfullySavedLog) {
Toast.makeText(getActivity(), getResources().getString(R.string.file_saved), Toast.LENGTH_SHORT).show();
ToastUtils.showToastInUiThread(requireContext(),R.string.file_saved);

saveTextSize(viewingTextView.getTextSize());
songViewFragmentViewModel.isEditedTextToSave = false;
songViewFragmentViewModel.filename = filename;

} else {
Toast.makeText(getActivity(), getResources().getString(R.string.unable_to_save_file), Toast.LENGTH_SHORT).show();
ToastUtils.showToastInUiThread(requireContext(),R.string.unable_to_save_file);
}
handlerThread.quit();
}
Expand All @@ -497,6 +497,8 @@ public void handleMessage(Message msg) {
asyncHandler.sendMessage(message);
};
asyncHandler.post(runnable);

saveTextSize(viewingTextView.getTextSize());
}

private void proceedAfterSaving(String callingMethod) {
Expand Down Expand Up @@ -1301,4 +1303,19 @@ public static class EditTextDialogViewModel extends ViewModel {
protected String chordText;
}
}
public static class ToastUtils {

public static void showToastInUiThread(final Context ctx,
final int stringRes) {

Handler mainThread = new Handler(Looper.getMainLooper());
mainThread.post(new Runnable() {
@Override
public void run() {
Toast.makeText(ctx, ctx.getString(stringRes), Toast.LENGTH_SHORT).show();
}
});
}
}

}

0 comments on commit 2251461

Please sign in to comment.