diff --git a/app/src/main/java/com/secuso/privacyFriendlyCodeScanner/qrscanner/ui/activities/ResultActivity.java b/app/src/main/java/com/secuso/privacyFriendlyCodeScanner/qrscanner/ui/activities/ResultActivity.java index ce45db7d..944d9f41 100644 --- a/app/src/main/java/com/secuso/privacyFriendlyCodeScanner/qrscanner/ui/activities/ResultActivity.java +++ b/app/src/main/java/com/secuso/privacyFriendlyCodeScanner/qrscanner/ui/activities/ResultActivity.java @@ -1,6 +1,7 @@ package com.secuso.privacyfriendlycodescanner.qrscanner.ui.activities; import android.app.Activity; +import android.arch.lifecycle.ViewModelProviders; import android.content.ClipData; import android.content.ClipboardManager; import android.content.Context; @@ -40,6 +41,7 @@ import com.secuso.privacyfriendlycodescanner.qrscanner.ui.resultfragments.TextResultFragment; import com.secuso.privacyfriendlycodescanner.qrscanner.ui.resultfragments.URLResultFragment; import com.secuso.privacyfriendlycodescanner.qrscanner.ui.resultfragments.WifiResultFragment; +import com.secuso.privacyfriendlycodescanner.qrscanner.ui.viewmodel.ResultViewModel; import static com.secuso.privacyfriendlycodescanner.qrscanner.helpers.PrefManager.PREF_SAVE_REAL_IMAGE_TO_HISTORY; @@ -76,6 +78,7 @@ public static void startResultActivity(@NonNull Context context, @NonNull Histor } private SharedPreferences mPreferences; + private ResultViewModel viewModel; private BarcodeResult currentBarcodeResult = null; private ResultFragment currentResultFragment = null; @@ -92,6 +95,8 @@ protected void onCreate(Bundle savedInstanceState) { mPreferences = PreferenceManager.getDefaultSharedPreferences(this); + viewModel = ViewModelProviders.of(this).get(ResultViewModel.class); + initOrRestoreState(savedInstanceState); ActionBar ab = getSupportActionBar(); @@ -148,6 +153,12 @@ private void initOrRestoreState(Bundle savedInstanceState) { mSavedToHistory = savedInstanceState.getBoolean("mSavedToHistory"); mParsedResult = ResultParser.parseResult(currentHistoryItem.getResult()); } + viewModel.currentBarcodeResult = currentBarcodeResult; + viewModel.currentHistoryItem = currentHistoryItem; + viewModel.currentResultFragment = currentResultFragment; + viewModel.mParsedResult = mParsedResult; + viewModel.mCodeImage = mCodeImage; + viewModel.mSavedToHistory = mSavedToHistory; } diff --git a/app/src/main/java/com/secuso/privacyFriendlyCodeScanner/qrscanner/ui/resultfragments/ResultFragment.java b/app/src/main/java/com/secuso/privacyFriendlyCodeScanner/qrscanner/ui/resultfragments/ResultFragment.java index d14462ef..1481b263 100644 --- a/app/src/main/java/com/secuso/privacyFriendlyCodeScanner/qrscanner/ui/resultfragments/ResultFragment.java +++ b/app/src/main/java/com/secuso/privacyFriendlyCodeScanner/qrscanner/ui/resultfragments/ResultFragment.java @@ -1,19 +1,41 @@ package com.secuso.privacyfriendlycodescanner.qrscanner.ui.resultfragments; +import android.arch.lifecycle.ViewModelProviders; import android.content.Context; import android.os.Bundle; import android.support.annotation.NonNull; +import android.support.annotation.Nullable; import android.support.v4.app.Fragment; import com.google.zxing.client.result.ParsedResult; +import com.secuso.privacyfriendlycodescanner.qrscanner.ui.viewmodel.ResultViewModel; public abstract class ResultFragment extends Fragment { protected ParsedResult parsedResult; + protected ResultViewModel viewModel; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); + + viewModel = ViewModelProviders.of(getActivity()).get(ResultViewModel.class); + } + + @Override + public void onAttach(Context context) { + super.onAttach(context); + + viewModel = ViewModelProviders.of(getActivity()).get(ResultViewModel.class); + parsedResult = viewModel.mParsedResult; + } + + @Override + public void onActivityCreated(@Nullable Bundle savedInstanceState) { + super.onActivityCreated(savedInstanceState); + + viewModel = ViewModelProviders.of(getActivity()).get(ResultViewModel.class); + parsedResult = viewModel.mParsedResult; } public void putQRCode(@NonNull ParsedResult parsedResult) { diff --git a/app/src/main/java/com/secuso/privacyFriendlyCodeScanner/qrscanner/ui/viewmodel/ResultViewModel.java b/app/src/main/java/com/secuso/privacyFriendlyCodeScanner/qrscanner/ui/viewmodel/ResultViewModel.java new file mode 100644 index 00000000..c9fd0f65 --- /dev/null +++ b/app/src/main/java/com/secuso/privacyFriendlyCodeScanner/qrscanner/ui/viewmodel/ResultViewModel.java @@ -0,0 +1,21 @@ +package com.secuso.privacyfriendlycodescanner.qrscanner.ui.viewmodel; + +import android.arch.lifecycle.ViewModel; +import android.graphics.Bitmap; + +import com.google.zxing.client.result.ParsedResult; +import com.journeyapps.barcodescanner.BarcodeResult; +import com.secuso.privacyfriendlycodescanner.qrscanner.database.HistoryItem; +import com.secuso.privacyfriendlycodescanner.qrscanner.ui.resultfragments.ResultFragment; + +public class ResultViewModel extends ViewModel { + + public BarcodeResult currentBarcodeResult = null; + public ResultFragment currentResultFragment = null; + + public HistoryItem currentHistoryItem = null; + public ParsedResult mParsedResult = null; + public Bitmap mCodeImage = null; + public boolean mSavedToHistory = false; + +}