Some improvements suggested by Codacy
This commit is contained in:
@ -0,0 +1,69 @@
|
||||
package ch.dissem.apps.abit.drawer;
|
||||
|
||||
import android.app.Dialog;
|
||||
import android.content.Context;
|
||||
import android.graphics.Point;
|
||||
import android.view.Display;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.Window;
|
||||
import android.view.WindowManager;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.RelativeLayout;
|
||||
|
||||
import com.mikepenz.materialdrawer.AccountHeader;
|
||||
import com.mikepenz.materialdrawer.model.interfaces.IProfile;
|
||||
|
||||
import ch.dissem.apps.abit.service.Singleton;
|
||||
import ch.dissem.apps.abit.util.Drawables;
|
||||
|
||||
public class ProfileImageListener implements AccountHeader.OnAccountHeaderProfileImageListener {
|
||||
private final Context ctx;
|
||||
|
||||
public ProfileImageListener(Context ctx) {
|
||||
this.ctx = ctx;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onProfileImageClick(View view, IProfile profile, boolean current) {
|
||||
if (current) {
|
||||
// Show QR code in modal dialog
|
||||
final Dialog dialog = new Dialog(ctx);
|
||||
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
|
||||
|
||||
ImageView imageView = new ImageView(ctx);
|
||||
imageView.setImageBitmap(Drawables.qrCode(Singleton.getIdentity(ctx)));
|
||||
imageView.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
dialog.dismiss();
|
||||
}
|
||||
});
|
||||
dialog.addContentView(imageView, new RelativeLayout.LayoutParams(
|
||||
ViewGroup.LayoutParams.MATCH_PARENT,
|
||||
ViewGroup.LayoutParams.MATCH_PARENT));
|
||||
Window window = dialog.getWindow();
|
||||
if (window != null) {
|
||||
Display display = window.getWindowManager().getDefaultDisplay();
|
||||
Point size = new Point();
|
||||
display.getSize(size);
|
||||
int dim = size.x < size.y ? size.x : size.y;
|
||||
|
||||
WindowManager.LayoutParams lp = new WindowManager.LayoutParams();
|
||||
lp.copyFrom(window.getAttributes());
|
||||
lp.width = dim;
|
||||
lp.height = dim;
|
||||
|
||||
window.setAttributes(lp);
|
||||
}
|
||||
dialog.show();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onProfileImageLongClick(View view, IProfile iProfile, boolean b) {
|
||||
return false;
|
||||
}
|
||||
}
|
@ -0,0 +1,65 @@
|
||||
package ch.dissem.apps.abit.drawer;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.support.v4.app.FragmentManager;
|
||||
import android.view.View;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.mikepenz.materialdrawer.AccountHeader;
|
||||
import com.mikepenz.materialdrawer.model.ProfileDrawerItem;
|
||||
import com.mikepenz.materialdrawer.model.interfaces.IProfile;
|
||||
|
||||
import ch.dissem.apps.abit.AddressDetailActivity;
|
||||
import ch.dissem.apps.abit.AddressDetailFragment;
|
||||
import ch.dissem.apps.abit.MainActivity;
|
||||
import ch.dissem.apps.abit.R;
|
||||
import ch.dissem.apps.abit.dialog.AddIdentityDialogFragment;
|
||||
import ch.dissem.apps.abit.service.Singleton;
|
||||
import ch.dissem.bitmessage.entity.BitmessageAddress;
|
||||
|
||||
import static android.widget.Toast.LENGTH_LONG;
|
||||
|
||||
public class ProfileSelectionListener implements AccountHeader.OnAccountHeaderListener {
|
||||
private final Context ctx;
|
||||
private final FragmentManager fragmentManager;
|
||||
|
||||
public ProfileSelectionListener(Context ctx, FragmentManager fragmentManager) {
|
||||
this.ctx = ctx;
|
||||
this.fragmentManager = fragmentManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onProfileChanged(View view, IProfile profile, boolean current) {
|
||||
switch ((int) profile.getIdentifier()) {
|
||||
case MainActivity.ADD_IDENTITY:
|
||||
addIdentityDialog();
|
||||
break;
|
||||
case MainActivity.MANAGE_IDENTITY:
|
||||
BitmessageAddress identity = Singleton.getIdentity(ctx);
|
||||
if (identity == null) {
|
||||
Toast.makeText(ctx, R.string.no_identity_warning, LENGTH_LONG).show();
|
||||
} else {
|
||||
Intent show = new Intent(ctx, AddressDetailActivity.class);
|
||||
show.putExtra(AddressDetailFragment.ARG_ITEM, identity);
|
||||
ctx.startActivity(show);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
if (profile instanceof ProfileDrawerItem) {
|
||||
Object tag = ((ProfileDrawerItem) profile).getTag();
|
||||
if (tag instanceof BitmessageAddress) {
|
||||
Singleton.setIdentity((BitmessageAddress) tag);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
// false if it should close the drawer
|
||||
return false;
|
||||
}
|
||||
|
||||
private void addIdentityDialog() {
|
||||
AddIdentityDialogFragment dialog = new AddIdentityDialogFragment();
|
||||
dialog.show(fragmentManager, "dialog");
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user