Vedroid36
4/13/2018 - 2:03 PM

ReportDetailsActivity.java

package itomych.com.jti.ui.reports.details;

import android.content.Context;
import android.content.Intent;
import android.databinding.ViewDataBinding;
import android.os.Bundle;
import android.support.v7.app.ActionBar;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;

import itomych.com.jti.R;
import itomych.com.jti.data.model.Report;
import itomych.com.jti.ui.base.BaseActivity;
import itomych.com.jti.ui.base.BaseFragment;
import itomych.com.jti.ui.reports.details.fragments.NoGpsWarningFragment;
import itomych.com.jti.ui.reports.details.fragments.ReportStatDialogFragment;
import itomych.com.jti.ui.tutorial.TutorialFragment;
import itomych.com.jti.util.ActivityUtils;
import itomych.com.jti.util.log.LogUtil;

/**
 * Created by alexischenko on 2/28/18.
 */

public class ReportDetailsActivity extends BaseActivity {

    public static final int CALLED_ADD_MANUAL = 0;
    public static final int CALLED_SHOW_SCANNER = 1;
    public static final int CALLED_SHOW_SAVED_REPORT = 2;

    private static final String KEY_CALL_TYPE = "key_call_type";
    private static final String KEY_REPORT = "key_report";
    private static final String TAG = ReportDetailsActivity.class.getSimpleName();

    private int callerType;
    private Report currentReport;


    public static Intent getLaunchIntent(Context context, Report report, int cameFrom) {
        Intent intent = new Intent(context, ReportDetailsActivity.class);
        intent.putExtra(KEY_REPORT, report);
        intent.putExtra(KEY_CALL_TYPE, cameFrom);
        return intent;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        currentReport = getIntent().getParcelableExtra(KEY_REPORT);
        callerType = getIntent().getIntExtra(KEY_CALL_TYPE, 0);
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
    }

    @Override
    protected int getContentView() {
        return R.layout.activity_base_layout;
    }

    @Override
    protected void setupDataBinding(ViewDataBinding dataBinding) {
    }

    @Override
    public void lunchPinCodeCheck() {
        super.lunchPinCodeCheck();
        LogUtil.d(TAG, "lunchPinCodeCheck");


        /** TODO alexischenko 4/9/18:  check we can hide No Gps Warning
        * case when user went to app settings and then went back to app thriugh pin-code screen */

        if (getFragmentManager().getBackStackEntryCount() >1) {
            if (getFragmentManager().getBackStackEntryAt(1) instanceof NoGpsWarningFragment) {
                getFragmentManager().popBackStack();
            }
        }

    }

    @Override
    protected BaseFragment onStartFragment() {
        ReportDetailsFragment fragment = ReportDetailsFragment.newInstance(currentReport, callerType);
        ActivityUtils.addFragmentToActivity(getSupportFragmentManager(), fragment, CONTENT_ID);
        return fragment;
    }

    @Override
    protected void initPresenter(BaseFragment fragment) {
        new ReportDetailsPresenterImpl((ReportDetailsContract.View) fragment, this, currentReport);
    }

    protected void setupActionBar(ActionBar actionBar) {
        actionBar.setDisplayHomeAsUpEnabled(true);
        actionBar.setTitle(CALLED_SHOW_SAVED_REPORT != callerType
                ? getResources().getString(R.string.action_button_report)
                : getResources().getString(R.string.action_button_report) + " " + currentReport.getFormattedDate());
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        MenuInflater inflater = getMenuInflater();
        inflater.inflate(R.menu.menu, menu);
        menu.findItem(R.id.action_report_stat).setVisible(currentReport.isSynced());
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) {
            case R.id.action_info:
                TutorialFragment tutorialFragment = new TutorialFragment();
                tutorialFragment.show(getSupportFragmentManager(), "");
                return true;
            case R.id.action_report_stat:
                ReportStatDialogFragment dialogFragment = ReportStatDialogFragment.newInstance(currentReport);
                dialogFragment.show(getSupportFragmentManager(), "");
                return true;
            default:
                return super.onOptionsItemSelected(item);
        }
    }

    @Override
    public void onBackPressed() {
        super.onBackPressed();
    }

}