@Override public void onRestoreInstanceState(Bundle savedInstanceState) { // Restore state super.onRestoreInstanceState(savedInstanceState); if (savedInstanceState != null) { targetId = savedInstanceState.getInt(REPORT_ID); categoryHolder = savedInstanceState.getInt(REPORT_CATEGORY, CATEGORY_NONE); type = savedInstanceState.getInt(REPORT_TYPE); targetName = savedInstanceState.getString(REPORT_USER); contentHolder = savedInstanceState.getString(REPORT_CONTENT); } }
@Override public void onSaveInstanceState(Bundle savedInstanceState) { // Save state super.onSaveInstanceState(savedInstanceState); savedInstanceState.putInt(REPORT_ID, targetId); savedInstanceState.putInt(REPORT_TYPE, type); savedInstanceState.putInt(REPORT_CATEGORY, reportCategorySelect.getCheckedRadioButtonId()); if (targetName != null) { savedInstanceState.putString(REPORT_USER, targetName); } if (reportContent != null) { savedInstanceState.putString(REPORT_CONTENT, reportContent.getText().toString()); } }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_report); // Either get data from intent or restore state if (getIntent() != null) { if (getIntent().getData() != null) { targetId = Integer.valueOf(getIntent().getData().getHost()); type = REPORT_TYPE_TASK; } else { targetId = getIntent().getIntExtra(REPORT_ID, 0); targetName = SparkleHelper.getNameFromId(getIntent().getStringExtra(REPORT_USER)); type = getIntent().getIntExtra(REPORT_TYPE, REPORT_TYPE_TASK); } } if (savedInstanceState != null) { targetId = savedInstanceState.getInt(REPORT_ID); targetName = savedInstanceState.getString(REPORT_USER); type = savedInstanceState.getInt(REPORT_TYPE); categoryHolder = savedInstanceState.getInt(REPORT_CATEGORY, CATEGORY_NONE); contentHolder = savedInstanceState.getString(REPORT_CONTENT); } Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar_report); setToolbar(toolbar); mSwipeRefreshLayout = (SwipeRefreshLayout) findViewById(R.id.report_refresher); mSwipeRefreshLayout.setColorSchemeResources(RaraHelper.getThemeRefreshColours(this)); mSwipeRefreshLayout.setEnabled(false); dialogListener = new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { mSwipeRefreshLayout.post( new Runnable() { @Override public void run() { mSwipeRefreshLayout.setRefreshing(true); sendReport(); } }); } }; view = findViewById(R.id.report_main); targetHolder = (RelativeLayout) findViewById(R.id.report_target_holder); reportTarget = (TextView) findViewById(R.id.report_target); reportCategoryHolder = (CardView) findViewById(R.id.report_category_holder); reportCategorySelect = (RadioGroup) findViewById(R.id.report_category); reportContent = (AppCompatEditText) findViewById(R.id.report_content); targetHolder.setVisibility(View.VISIBLE); reportCategoryHolder.setVisibility(View.VISIBLE); // If replying to mod mail, use this message instead if (type == REPORT_TYPE_TASK) { reportTarget.setText( String.format(Locale.US, getString(R.string.report_mod_reply), targetId)); reportCategoryHolder.setVisibility(View.GONE); } else { String reportType = ""; switch (type) { case REPORT_TYPE_RMB: reportType = getString(R.string.report_rmb_post); break; case REPORT_TYPE_TELEGRAM: reportType = getString(R.string.report_telegram); break; default: targetHolder.setVisibility(View.GONE); break; } reportTarget.setText( String.format( Locale.US, getString(R.string.report_target), reportType, targetId, targetName)); } if (categoryHolder != CATEGORY_NONE) { reportCategorySelect.check(categoryHolder); } if (contentHolder != null && contentHolder.length() > 0) { reportContent.setText(contentHolder); } }