Сделал возможность переключаться между приложениями и добавлять новые приложения практически не меняя код

This commit is contained in:
Ivan Murashov
2017-09-07 15:35:13 +03:00
parent 8d81fb185d
commit 361bcd48ce
22 changed files with 304 additions and 140 deletions

View File

@@ -37,6 +37,7 @@ import android.view.View;
import android.view.Window;
import android.widget.FrameLayout;
import android.widget.Toast;
import android.widget.TextView;
import com.dinect.checker.net.ApiClient;
@@ -59,7 +60,9 @@ public abstract class AbstractScannerActivity extends AppCompatActivity {
"Перестань!",
"Ну и зачем?..",
};
private final AtomicInteger counter = new AtomicInteger(0);
private int mColor;
public static final String SCAN_MODES = "SCAN_MODES";
public static final String ERROR_INFO = "ERROR_INFO";
@@ -115,6 +118,8 @@ public abstract class AbstractScannerActivity extends AppCompatActivity {
protected final void initToolbar(final int toolbarId, final @NonNull String title) {
Log.d(TAG, "initToolbar");
final Toolbar toolbar = (Toolbar) findViewById(toolbarId);
mColor = (int) getIntent().getLongExtra(MainActivity.PREF_APP_BAR_COLOR, 0xffffff);
toolbar.setBackgroundColor(mColor);
setSupportActionBar(toolbar);
final ActionBar actionBar = getSupportActionBar();
@@ -295,7 +300,7 @@ public abstract class AbstractScannerActivity extends AppCompatActivity {
@Override
public boolean onOptionsItemSelected(MenuItem item) {
if (item.getItemId() == R.id.logout) {
logoutDialog = new AbstractScannerActivity.LogoutDialogFragment();
logoutDialog = LogoutDialogFragment.newInstance(mColor);
logoutDialog.show(getFragmentManager(), "logout");
return true;
} else if (item.getItemId() == R.id.faq) {
@@ -324,14 +329,25 @@ public abstract class AbstractScannerActivity extends AppCompatActivity {
public static class LogoutDialogFragment extends DialogFragment {
static LogoutDialogFragment newInstance(int color) {
LogoutDialogFragment f = new LogoutDialogFragment();
Bundle bundle = new Bundle();
bundle.putInt(MainActivity.PREF_APP_BAR_COLOR, color);
f.setArguments(bundle);
return f;
}
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
final AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
final LayoutInflater inflater = getActivity().getLayoutInflater();
final View content = inflater.inflate(R.layout.f_logout_dialog, null);
builder.setView(content);
final View positiveButton = content.findViewById(R.id.positiveButton);
final View negativeButton = content.findViewById(R.id.negativeButton);
final TextView positiveButton = (TextView) content.findViewById(R.id.positiveButton);
final TextView negativeButton = (TextView) content.findViewById(R.id.negativeButton);
// Можно делать через стили, но я не уверен, что необходимо в нашем случае
positiveButton.setTextColor(getArguments().getInt(MainActivity.PREF_APP_BAR_COLOR));
negativeButton.setTextColor(getArguments().getInt(MainActivity.PREF_APP_BAR_COLOR));
negativeButton.setOnClickListener(new View.OnClickListener() {
@Override

View File

@@ -29,12 +29,14 @@ public class MainActivity extends FlutterActivity {
static final String TAG = "Checker.MainActivity";
private static final int START_SCANNER_REQUEST_CODE = 2017;
private static final String PREF_POS_MERCHANT_ID = "pref_pos_merchant_id";
private static final String PREF_DOC_ID = "pref_doc_id";
private static final String PREF_POS_ID = "pref_pos_id";
static final String PREF_API_URL = "prefs_api_token";
static final String PREF_APP_TOKEN = "pres_app_token";
static final String PREF_POS_TOKEN = "pref_pos_token";
static final String PREF_APP_BAR_COLOR = "pref_app_bar_color";
static final Class[] SCANNER_BACKEND = {
ScannerActivity.class,
@@ -77,6 +79,9 @@ public class MainActivity extends FlutterActivity {
case "getLocale":
result.success(BuildConfig.locale);
break;
case "getFlavor":
result.success(BuildConfig.flavor);
break;
case "getMerchantID":
result.success(mPreferences.getString(PREF_POS_MERCHANT_ID, null));
break;
@@ -88,6 +93,7 @@ public class MainActivity extends FlutterActivity {
cameraIntent.putExtra(PREF_API_URL, (String) arguments.get("url"));
cameraIntent.putExtra(PREF_APP_TOKEN, (String) arguments.get("appToken"));
cameraIntent.putExtra(PREF_POS_TOKEN, (String) arguments.get("token"));
cameraIntent.putExtra(PREF_APP_BAR_COLOR, (Long) arguments.get("color"));
startActivityForResult(cameraIntent, START_SCANNER_REQUEST_CODE);
break;
case "removeKeys":
@@ -172,6 +178,10 @@ public class MainActivity extends FlutterActivity {
}
public void getFlavor() {
}
public void getLocale() {
}

View File

@@ -45,7 +45,6 @@
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="#eb0004"
app:titleTextColor="@android:color/white" />
<View

View File

@@ -10,7 +10,6 @@
android:id="@+id/zxingToolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="#eb0004"
app:titleTextColor="@android:color/white" />
<View