Search in sources :

Example 1 with DeviceInfoDialog

use of com.genonbeta.TrebleShot.dialog.DeviceInfoDialog in project TrebleShot by genonbeta.

the class TransactionActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_transaction);
    mDatabase = new AccessDatabase(this);
    mTransactionFragment = (TransactionListFragment) getSupportFragmentManager().findFragmentById(R.id.activity_transaction_listfragment_transaction);
    mPathView = findViewById(R.id.activity_transaction_explorer_recycler);
    mHomeButton = findViewById(R.id.activity_transaction_explorer_image_home);
    mPowafulActionMode = findViewById(R.id.activity_transaction_action_mode);
    // mPowafulActionMode.setContainerLayout(findViewById(R.id.activity_transaction_action_mode_container));
    final Toolbar toolbar = findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    mDrawerLayout = findViewById(R.id.drawer_layout);
    if (mDrawerLayout != null) {
        ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(this, mDrawerLayout, toolbar, R.string.text_navigationDrawerOpen, R.string.text_navigationDrawerClose);
        mDrawerLayout.addDrawerListener(toggle);
        toggle.syncState();
    }
    mNavigationView = findViewById(R.id.nav_view);
    mNavigationView.setNavigationItemSelectedListener(this);
    mPathView.setHasFixedSize(true);
    mFilter.addAction(AccessDatabase.ACTION_DATABASE_CHANGE);
    mLayoutManager = new LinearLayoutManager(this, LinearLayoutManager.HORIZONTAL, false);
    mPathAdapter = new TransactionPathResolverRecyclerAdapter();
    mPathView.setLayoutManager(mLayoutManager);
    mLayoutManager.setStackFromEnd(true);
    mPathView.setAdapter(mPathAdapter);
    mPowafulActionMode.setOnSelectionTaskListener(new PowerfulActionMode.OnSelectionTaskListener() {

        @Override
        public void onSelectionTask(boolean started, PowerfulActionMode actionMode) {
            toolbar.setVisibility(!started ? View.VISIBLE : View.GONE);
        }
    });
    mPathAdapter.setOnClickListener(new PathResolverRecyclerAdapter.OnClickListener<String>() {

        @Override
        public void onClick(PathResolverRecyclerAdapter.Holder<String> holder) {
            goPath(holder.index.object);
        }
    });
    mHomeButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            goPath(null);
        }
    });
    if (ACTION_LIST_TRANSFERS.equals(getIntent().getAction()) && getIntent().hasExtra(EXTRA_GROUP_ID)) {
        TransactionObject.Group group = new TransactionObject.Group(getIntent().getIntExtra(EXTRA_GROUP_ID, -1));
        try {
            mDatabase.reconstruct(group);
            NetworkDevice networkDevice = new NetworkDevice(group.deviceId);
            mDatabase.reconstruct(networkDevice);
            mGroup = group;
            mDevice = networkDevice;
            mInfoDialog = new TransactionGroupInfoDialog(this, mDatabase, mGroup);
            if (getSupportActionBar() != null)
                getSupportActionBar().setTitle(mDevice.nickname);
            mTransactionFragment.getAdapter().setPathChangedListener(this);
            applyPath(null);
            View headerView = mNavigationView.getHeaderView(0);
            View layoutView = headerView.findViewById(R.id.header_default_device_container);
            ImageView imageView = headerView.findViewById(R.id.header_default_device_image);
            TextView deviceNameText = headerView.findViewById(R.id.header_default_device_name_text);
            TextView versionText = headerView.findViewById(R.id.header_default_device_version_text);
            String firstLetters = TextUtils.getFirstLetters(mDevice.nickname, 1);
            TextDrawable drawable = TextDrawable.builder().buildRoundRect(firstLetters.length() > 0 ? firstLetters : "?", ContextCompat.getColor(getApplicationContext(), R.color.networkDeviceRipple), 100);
            layoutView.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View view) {
                    new DeviceInfoDialog(TransactionActivity.this, mDatabase, mDevice).show();
                    if (mDrawerLayout != null)
                        mDrawerLayout.closeDrawer(Gravity.START);
                }
            });
            imageView.setImageDrawable(drawable);
            deviceNameText.setText(mDevice.nickname);
            versionText.setText(mDevice.versionName);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    if (mGroup == null)
        finish();
}
Also used : TextDrawable(com.amulyakhare.textdrawable.TextDrawable) NetworkDevice(com.genonbeta.TrebleShot.object.NetworkDevice) ActionBarDrawerToggle(android.support.v7.app.ActionBarDrawerToggle) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) TransactionObject(com.genonbeta.TrebleShot.object.TransactionObject) TransactionGroupInfoDialog(com.genonbeta.TrebleShot.dialog.TransactionGroupInfoDialog) TextView(android.widget.TextView) ImageView(android.widget.ImageView) Toolbar(android.support.v7.widget.Toolbar) PowerfulActionMode(com.genonbeta.TrebleShot.widget.PowerfulActionMode) NavigationView(android.support.design.widget.NavigationView) ImageView(android.widget.ImageView) View(android.view.View) TextView(android.widget.TextView) RecyclerView(android.support.v7.widget.RecyclerView) IOException(java.io.IOException) PathResolverRecyclerAdapter(com.genonbeta.TrebleShot.adapter.PathResolverRecyclerAdapter) DeviceInfoDialog(com.genonbeta.TrebleShot.dialog.DeviceInfoDialog) AccessDatabase(com.genonbeta.TrebleShot.database.AccessDatabase)

Example 2 with DeviceInfoDialog

use of com.genonbeta.TrebleShot.dialog.DeviceInfoDialog in project TrebleShot by genonbeta.

the class NetworkDeviceListFragment method onListItemClick.

@Override
public void onListItemClick(ListView l, View v, int position, long id) {
    super.onListItemClick(l, v, position, id);
    final NetworkDevice device = (NetworkDevice) getAdapter().getItem(position);
    if (mClickListener != null) {
        if (device.versionNumber != -1 && device.versionNumber < AppConfig.SUPPORTED_MIN_VERSION)
            createSnackbar(R.string.mesg_versionNotSupported).show();
        else
            mClickListener.onItemClick(l, v, position, id);
    } else if (device instanceof NetworkDeviceListAdapter.HotspotNetwork) {
        final NetworkDeviceListAdapter.HotspotNetwork hotspotNetwork = (NetworkDeviceListAdapter.HotspotNetwork) device;
        AlertDialog.Builder builder = new AlertDialog.Builder(getContext());
        builder.setTitle(hotspotNetwork.nickname);
        builder.setMessage(R.string.text_trebleshotHotspotDescription);
        builder.setNegativeButton(R.string.butn_close, null);
        builder.setPositiveButton(isConnectedToNetwork(hotspotNetwork) ? R.string.butn_disconnect : R.string.butn_connect, new DialogInterface.OnClickListener() {

            @Override
            public void onClick(DialogInterface dialog, int which) {
                toggleConnection(hotspotNetwork);
            }
        });
        builder.show();
    } else if (device.brand != null && device.model != null)
        new DeviceInfoDialog(getActivity(), getAdapter().getDatabase(), device).show();
}
Also used : AlertDialog(android.support.v7.app.AlertDialog) DialogInterface(android.content.DialogInterface) DeviceInfoDialog(com.genonbeta.TrebleShot.dialog.DeviceInfoDialog) NetworkDevice(com.genonbeta.TrebleShot.object.NetworkDevice) NetworkDeviceListAdapter(com.genonbeta.TrebleShot.adapter.NetworkDeviceListAdapter)

Aggregations

DeviceInfoDialog (com.genonbeta.TrebleShot.dialog.DeviceInfoDialog)2 NetworkDevice (com.genonbeta.TrebleShot.object.NetworkDevice)2 DialogInterface (android.content.DialogInterface)1 NavigationView (android.support.design.widget.NavigationView)1 ActionBarDrawerToggle (android.support.v7.app.ActionBarDrawerToggle)1 AlertDialog (android.support.v7.app.AlertDialog)1 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)1 RecyclerView (android.support.v7.widget.RecyclerView)1 Toolbar (android.support.v7.widget.Toolbar)1 View (android.view.View)1 ImageView (android.widget.ImageView)1 TextView (android.widget.TextView)1 TextDrawable (com.amulyakhare.textdrawable.TextDrawable)1 NetworkDeviceListAdapter (com.genonbeta.TrebleShot.adapter.NetworkDeviceListAdapter)1 PathResolverRecyclerAdapter (com.genonbeta.TrebleShot.adapter.PathResolverRecyclerAdapter)1 AccessDatabase (com.genonbeta.TrebleShot.database.AccessDatabase)1 TransactionGroupInfoDialog (com.genonbeta.TrebleShot.dialog.TransactionGroupInfoDialog)1 TransactionObject (com.genonbeta.TrebleShot.object.TransactionObject)1 PowerfulActionMode (com.genonbeta.TrebleShot.widget.PowerfulActionMode)1 IOException (java.io.IOException)1