Search in sources :

Example 1 with SimpleItemTouchHelperCallback

use of org.shadowice.flocke.andotp.View.ItemTouchHelper.SimpleItemTouchHelperCallback in project andOTP by andOTP.

the class MainActivity method onCreate.

// Initialize the main application
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setTitle(R.string.app_name);
    if (!settings.getScreenshotsEnabled())
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_SECURE, WindowManager.LayoutParams.FLAG_SECURE);
    setContentView(R.layout.activity_main);
    Toolbar toolbar = findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    PreferenceManager.setDefaultValues(this, R.xml.preferences, false);
    settings.registerPreferenceChangeListener(this);
    encryptionType = settings.getEncryption();
    if (settings.getAuthMethod() != AuthMethod.NONE && savedInstanceState == null)
        requireAuthentication = true;
    setBroadcastCallback(new BroadcastReceivedCallback() {

        @Override
        public void onReceivedScreenOff() {
            if (settings.getRelockOnScreenOff() && settings.getAuthMethod() != AuthMethod.NONE)
                requireAuthentication = true;
        }
    });
    if (!settings.getFirstTimeWarningShown()) {
        showFirstTimeWarning();
    }
    fabsMenu = findViewById(R.id.fabs_menu);
    TitleFAB qrFAB = findViewById(R.id.fab_qr_scan);
    qrFAB.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            fabsMenu.collapse();
            scanQRCode();
        }
    });
    TitleFAB manualFAB = findViewById(R.id.fab_manual_entry);
    manualFAB.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            fabsMenu.collapse();
            ManualEntryDialog.show(MainActivity.this, settings, adapter);
        }
    });
    final ProgressBar progressBar = findViewById(R.id.progressBar);
    RecyclerView recList = findViewById(R.id.cardList);
    recList.setHasFixedSize(true);
    LinearLayoutManager llm = new LinearLayoutManager(this);
    llm.setOrientation(LinearLayoutManager.VERTICAL);
    recList.setLayoutManager(llm);
    tagsDrawerAdapter = new TagsAdapter(this, new HashMap<String, Boolean>());
    adapter = new EntriesCardAdapter(this, tagsDrawerAdapter);
    recList.setAdapter(adapter);
    touchHelperCallback = new SimpleItemTouchHelperCallback(adapter);
    ItemTouchHelper touchHelper = new ItemTouchHelper(touchHelperCallback);
    touchHelper.attachToRecyclerView(recList);
    NotificationHelper.initializeNotificationChannels(this);
    restoreSortMode();
    float durationScale = android.provider.Settings.Global.getFloat(this.getContentResolver(), android.provider.Settings.Global.ANIMATOR_DURATION_SCALE, 0);
    if (durationScale == 0)
        durationScale = 1;
    final long animatorDuration = (long) (1000 / durationScale);
    adapter.setCallback(new EntriesCardAdapter.Callback() {

        @Override
        public void onMoveEventStart() {
            stopUpdater();
        }

        @Override
        public void onMoveEventStop() {
            startUpdater();
        }
    });
    handler = new Handler();
    handlerTask = new Runnable() {

        @Override
        public void run() {
            int progress = (int) (TokenCalculator.TOTP_DEFAULT_PERIOD - (System.currentTimeMillis() / 1000) % TokenCalculator.TOTP_DEFAULT_PERIOD);
            progressBar.setProgress(progress * 100);
            ObjectAnimator animation = ObjectAnimator.ofInt(progressBar, "progress", (progress - 1) * 100);
            animation.setDuration(animatorDuration);
            animation.setInterpolator(new LinearInterpolator());
            animation.start();
            adapter.updateTokens();
            handler.postDelayed(this, 1000);
        }
    };
    setupDrawer();
}
Also used : TagsAdapter(org.shadowice.flocke.andotp.View.TagsAdapter) HashMap(java.util.HashMap) SimpleItemTouchHelperCallback(org.shadowice.flocke.andotp.View.ItemTouchHelper.SimpleItemTouchHelperCallback) ObjectAnimator(android.animation.ObjectAnimator) Handler(android.os.Handler) TitleFAB(jahirfiquitiva.libs.fabsmenu.TitleFAB) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) SearchView(android.support.v7.widget.SearchView) View(android.view.View) AdapterView(android.widget.AdapterView) RecyclerView(android.support.v7.widget.RecyclerView) CheckedTextView(android.widget.CheckedTextView) ListView(android.widget.ListView) ItemTouchHelper(android.support.v7.widget.helper.ItemTouchHelper) LinearInterpolator(android.view.animation.LinearInterpolator) EntriesCardAdapter(org.shadowice.flocke.andotp.View.EntriesCardAdapter) RecyclerView(android.support.v7.widget.RecyclerView) ProgressBar(android.widget.ProgressBar) Toolbar(android.support.v7.widget.Toolbar)

Aggregations

ObjectAnimator (android.animation.ObjectAnimator)1 Handler (android.os.Handler)1 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)1 RecyclerView (android.support.v7.widget.RecyclerView)1 SearchView (android.support.v7.widget.SearchView)1 Toolbar (android.support.v7.widget.Toolbar)1 ItemTouchHelper (android.support.v7.widget.helper.ItemTouchHelper)1 View (android.view.View)1 LinearInterpolator (android.view.animation.LinearInterpolator)1 AdapterView (android.widget.AdapterView)1 CheckedTextView (android.widget.CheckedTextView)1 ListView (android.widget.ListView)1 ProgressBar (android.widget.ProgressBar)1 TitleFAB (jahirfiquitiva.libs.fabsmenu.TitleFAB)1 HashMap (java.util.HashMap)1 EntriesCardAdapter (org.shadowice.flocke.andotp.View.EntriesCardAdapter)1 SimpleItemTouchHelperCallback (org.shadowice.flocke.andotp.View.ItemTouchHelper.SimpleItemTouchHelperCallback)1 TagsAdapter (org.shadowice.flocke.andotp.View.TagsAdapter)1