package net.ktnx.mobileledger.ui.templates;
import android.annotation.SuppressLint;
+import android.content.Context;
import android.content.res.Resources;
import android.text.Editable;
import android.text.TextWatcher;
import net.ktnx.mobileledger.db.AccountAutocompleteAdapter;
import net.ktnx.mobileledger.model.Data;
import net.ktnx.mobileledger.model.TemplateDetailsItem;
-import net.ktnx.mobileledger.ui.QRScanCapableFragment;
+import net.ktnx.mobileledger.ui.QR;
import net.ktnx.mobileledger.ui.TemplateDetailSourceSelectorFragment;
import net.ktnx.mobileledger.utils.Logger;
import net.ktnx.mobileledger.utils.Misc;
}
private void scanTestQR(View view) {
- QRScanCapableFragment.triggerQRScan();
+ Context ctx = view.getContext();
+ if (ctx instanceof QR.QRScanTrigger)
+ ((QR.QRScanTrigger) ctx).triggerQRScan();
}
}
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
+import androidx.fragment.app.Fragment;
import androidx.lifecycle.ViewModelProvider;
import androidx.lifecycle.ViewModelStoreOwner;
import androidx.navigation.NavController;
import net.ktnx.mobileledger.R;
import net.ktnx.mobileledger.databinding.TemplateDetailsFragmentBinding;
-import net.ktnx.mobileledger.ui.QRScanCapableFragment;
import net.ktnx.mobileledger.utils.Logger;
-public class TemplateDetailsFragment extends QRScanCapableFragment {
+public class TemplateDetailsFragment extends Fragment {
static final String ARG_TEMPLATE_ID = "pattern-id";
private static final String ARG_COLUMN_COUNT = "column-count";
private TemplateDetailsFragmentBinding b;
return b.getRoot();
}
- @Override
- protected void onQrScanned(String text) {
- Logger.debug("PatDet_fr", String.format("Got scanned text '%s'", text));
- if (text != null)
- mViewModel.setTestText(text);
- }
interface InteractionListener {
void onDeleteTemplate(@NonNull Long templateId);
}
import android.os.Bundle;
import android.view.MenuItem;
+import androidx.activity.result.ActivityResultLauncher;
import androidx.annotation.NonNull;
import androidx.appcompat.app.ActionBar;
import androidx.lifecycle.ViewModelProvider;
import net.ktnx.mobileledger.databinding.ActivityTemplatesBinding;
import net.ktnx.mobileledger.db.DB;
import net.ktnx.mobileledger.db.TemplateWithAccounts;
+import net.ktnx.mobileledger.ui.QR;
import net.ktnx.mobileledger.ui.activity.CrashReportingActivity;
import net.ktnx.mobileledger.utils.Logger;
public class TemplatesActivity extends CrashReportingActivity
implements TemplateListFragment.OnTemplateListFragmentInteractionListener,
- TemplateDetailsFragment.InteractionListener {
+ TemplateDetailsFragment.InteractionListener, QR.QRScanResultReceiver, QR.QRScanTrigger {
public static final String ARG_ADD_TEMPLATE = "add-template";
private ActivityTemplatesBinding b;
private NavController navController;
+ private ActivityResultLauncher<Void> qrScanLauncher;
// @Override
// public boolean onCreateOptionsMenu(Menu menu) {
// super.onCreateOptionsMenu(menu);
b.fabAdd.setOnClickListener(v -> onEditTemplate(null));
b.fabSave.setOnClickListener(v -> onSaveTemplate());
+
+ qrScanLauncher = QR.registerLauncher(this, this);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
});
});
}
+ @Override
+ public void onQRScanResult(String scanned) {
+ Logger.debug("PatDet_fr", String.format("Got scanned text '%s'", scanned));
+ TemplateDetailsViewModel model = new ViewModelProvider(
+ navController.getViewModelStoreOwner(R.id.template_list_navigation)).get(
+ TemplateDetailsViewModel.class);
+ model.setTestText(scanned);
+ }
+ @Override
+ public void triggerQRScan() {
+ qrScanLauncher.launch(null);
+ }
}
\ No newline at end of file