Fully migrated to Kotlin

This commit is contained in:
2017-08-25 20:24:25 +02:00
parent 852e38b97d
commit cc18f34161
104 changed files with 5064 additions and 6111 deletions

View File

@ -1,69 +0,0 @@
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;
}
}

View File

@ -0,0 +1,59 @@
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
class ProfileImageListener(private val ctx: Context) : AccountHeader.OnAccountHeaderProfileImageListener {
override fun onProfileImageClick(view: View, profile: IProfile<*>, current: Boolean): Boolean {
if (current) {
// Show QR code in modal dialog
val dialog = Dialog(ctx)
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE)
val imageView = ImageView(ctx)
imageView.setImageBitmap(Drawables.qrCode(Singleton.getIdentity(ctx)))
imageView.setOnClickListener { dialog.dismiss() }
dialog.addContentView(
imageView,
RelativeLayout.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.MATCH_PARENT
)
)
val window = dialog.window
if (window != null) {
val display = window.windowManager.defaultDisplay
val size = Point()
display.getSize(size)
val dim = if (size.x < size.y) size.x else size.y
val lp = WindowManager.LayoutParams()
lp.copyFrom(window.attributes)
lp.width = dim
lp.height = dim
window.attributes = lp
}
dialog.show()
return true
}
return false
}
override fun onProfileImageLongClick(view: View, iProfile: IProfile<*>, b: Boolean) = false
}

View File

@ -1,65 +0,0 @@
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");
}
}

View File

@ -0,0 +1,55 @@
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 android.widget.Toast.LENGTH_LONG
class ProfileSelectionListener(
private val ctx: Context,
private val fragmentManager: FragmentManager
) : AccountHeader.OnAccountHeaderListener {
override fun onProfileChanged(view: View, profile: IProfile<*>, current: Boolean): Boolean {
when (profile.identifier.toInt()) {
MainActivity.ADD_IDENTITY -> addIdentityDialog()
MainActivity.MANAGE_IDENTITY -> {
val identity = Singleton.getIdentity(ctx)
if (identity == null) {
Toast.makeText(ctx, R.string.no_identity_warning, LENGTH_LONG).show()
} else {
val show = Intent(ctx, AddressDetailActivity::class.java)
show.putExtra(AddressDetailFragment.ARG_ITEM, identity)
ctx.startActivity(show)
}
}
else -> if (profile is ProfileDrawerItem) {
val tag = profile.tag
if (tag is BitmessageAddress) {
Singleton.setIdentity(tag)
}
}
}
// false if it should close the drawer
return false
}
private fun addIdentityDialog() {
AddIdentityDialogFragment().show(fragmentManager, "dialog")
}
}