fixed thread problem; added QrReviewFragment; added more strings for multilanguage support

pull/5/head
Felix Prahl-Kamps 2018-06-17 14:00:27 +02:00
parent 70dbbeb479
commit 995e1070f5
7 changed files with 141 additions and 72 deletions

View File

@ -1,26 +1,14 @@
package de.overview.wg.its.mispauth.activity;
import android.content.DialogInterface;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import de.overview.wg.its.mispauth.R;
import de.overview.wg.its.mispauth.auxiliary.OrganisationDialog;
import de.overview.wg.its.mispauth.auxiliary.PreferenceManager;
import de.overview.wg.its.mispauth.fragment.ScanQrFragment;
import de.overview.wg.its.mispauth.fragment.ShowQrFragment;
import de.overview.wg.its.mispauth.fragment.SyncStartFragment;
import de.overview.wg.its.mispauth.fragment.UploadFragment;
import de.overview.wg.its.mispauth.model.Organisation;
import org.json.JSONException;
import org.json.JSONObject;
import de.overview.wg.its.mispauth.fragment.*;
public class SyncActivity extends AppCompatActivity {
@ -84,13 +72,19 @@ public class SyncActivity extends AppCompatActivity {
case 0:
prevButton.setEnabled(false);
nextButton.setEnabled(false);
prevButton.setText(R.string.back);
nextButton.setText(R.string.next);
transaction.replace(R.id.fragmentContainer, new SyncStartFragment());
break;
case 1:
prevButton.setEnabled(true);
prevButton.setText(R.string.back);
nextButton.setText(R.string.next);
if (partnerChoice == 1) {
nextButton.setEnabled(false);
@ -109,6 +103,10 @@ public class SyncActivity extends AppCompatActivity {
prevButton.setEnabled(true);
nextButton.setEnabled(true);
prevButton.setText(R.string.back);
nextButton.setText(R.string.next);
transaction.replace(R.id.fragmentContainer, new ShowQrFragment(), "FRAGMENT_SHOW");
} else {
@ -116,14 +114,27 @@ public class SyncActivity extends AppCompatActivity {
prevButton.setEnabled(true);
nextButton.setEnabled(false);
prevButton.setText(R.string.back);
nextButton.setText(R.string.next);
transaction.replace(R.id.fragmentContainer, new ScanQrFragment(), "FRAGMENT_SCAN");
}
break;
case 3:
prevButton.setEnabled(true);
nextButton.setEnabled(true);
nextButton.setText("Finish");
nextButton.setEnabled(false);
prevButton.setText(R.string.reject);
nextButton.setText(R.string.accept);
transaction.replace(R.id.fragmentContainer, new ReviewQrFragment());
break;
case 4:
nextButton.setText(R.string.done);
nextButton.setEnabled(true);
transaction.replace(R.id.fragmentContainer, new UploadFragment());
@ -148,19 +159,33 @@ public class SyncActivity extends AppCompatActivity {
public void setScannedQr(String qr) {
final FragmentManager manager = getSupportFragmentManager();
final ScanQrFragment scanFragment = (ScanQrFragment) manager.findFragmentByTag("FRAGMENT_SCAN");
scanFragment.setReadQr(false);
try {
OrganisationDialog d = new OrganisationDialog(this);
Organisation o = new Organisation();
o.fromJSON(new JSONObject(qr));
d.createDialog(o);
} catch (JSONException e) {
e.printStackTrace();
runOnUiThread(new Runnable() {
@Override
public void run() {
getFragment(3, true);
}
});
// try {
// OrganisationDialog d = new OrganisationDialog(this);
// Organisation o = new Organisation();
// o.fromJSON(new JSONObject(qr));
// d.createAcceptDialog(o, new OrganisationDialog.DialogCallback() {
// @Override
// public void onAccept() {
// nextButton.setEnabled(true);
// }
//
// @Override
// public void onReject() {
// scanFragment.setReadQr(true);
// scanFragment.openCamera();
// }
// });
//
// } catch (JSONException e) {
// e.printStackTrace();
// }
}

View File

@ -2,7 +2,6 @@ package de.overview.wg.its.mispauth.adapter;
import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v7.app.AlertDialog;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
@ -39,7 +38,7 @@ public class ExtOrgAdapter extends RecyclerView.Adapter<ExtOrgAdapter.ViewHolder
@Override
public void onClick(View v) {
OrganisationDialog d = new OrganisationDialog(context);
d.createDialog(dataSet[position]);
d.createInfoDialog(dataSet[position]);
}
});
}

View File

@ -2,6 +2,7 @@ package de.overview.wg.its.mispauth.auxiliary;
import android.app.Activity;
import android.content.Context;
import android.content.DialogInterface;
import android.support.v7.app.AlertDialog;
import android.view.LayoutInflater;
import android.view.View;
@ -19,7 +20,7 @@ public class OrganisationDialog {
inflater = ((Activity)context).getLayoutInflater();
}
public void createDialog(Organisation org) {
public void createInfoDialog(Organisation org) {
View dialogContent = inflater.inflate(R.layout.view_holder_organisation, null);
dialogBuilder.setView(dialogContent);
@ -42,9 +43,52 @@ public class OrganisationDialog {
TextView userCount = dialogContent.findViewById(R.id.organisation_user_count);
userCount.setText("" + org.getUserCount());
dialogBuilder.setPositiveButton("OK", null);
dialogBuilder.setCancelable(true);
dialogBuilder.create().show();
}
public void createAcceptDialog(Organisation org, final DialogCallback callback) {
View dialogContent = inflater.inflate(R.layout.view_holder_organisation, null);
dialogBuilder.setView(dialogContent);
TextView title = dialogContent.findViewById(R.id.organisation_title);
title.setText(org.getName());
TextView uuid = dialogContent.findViewById(R.id.organisation_uuid);
uuid.setText(org.getUuid());
TextView description = dialogContent.findViewById(R.id.organisation_description);
description.setText(org.getDescription());
TextView sector = dialogContent.findViewById(R.id.organisation_sector);
sector.setText(org.getSector());
TextView nationality = dialogContent.findViewById(R.id.organisation_nationality);
nationality.setText(org.getNationality());
TextView userCount = dialogContent.findViewById(R.id.organisation_user_count);
userCount.setText("" + org.getUserCount());
dialogBuilder.setNegativeButton("REJECT", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
callback.onReject();
}
});
dialogBuilder.setPositiveButton("ACCEPT", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
callback.onAccept();
}
});
dialogBuilder.setCancelable(false);
dialogBuilder.setNegativeButton("REJECT", null);
dialogBuilder.setPositiveButton("ACCEPT", null);
dialogBuilder.show();
dialogBuilder.create().show();
}
public interface DialogCallback {
void onAccept();
void onReject();
}
}

View File

@ -1,38 +0,0 @@
package de.overview.wg.its.mispauth.custom_viewpager;
import android.content.Context;
import android.support.v4.view.ViewPager;
import android.util.AttributeSet;
import android.view.MotionEvent;
public class ExtendedViewPager extends ViewPager {
private boolean enabled;
public ExtendedViewPager(Context context, AttributeSet attrs) {
super(context, attrs);
this.enabled = true;
}
@Override
public boolean onTouchEvent(MotionEvent event) {
if (this.enabled) {
return super.onTouchEvent(event);
}
return false;
}
@Override
public boolean onInterceptTouchEvent(MotionEvent event) {
if (this.enabled) {
return super.onInterceptTouchEvent(event);
}
return false;
}
public void setPagingEnabled(boolean enabled) {
this.enabled = enabled;
}
}

View File

@ -0,0 +1,20 @@
package de.overview.wg.its.mispauth.fragment;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import de.overview.wg.its.mispauth.R;
public class ReviewQrFragment extends Fragment {
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.fragment_review_qr, null);
return v;
}
}

View File

@ -0,0 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="REVIEW QR"/>
</android.support.constraint.ConstraintLayout>

View File

@ -11,4 +11,11 @@
<string name="title_activity_settings">Settings</string>
<string name="title_activity_sync">Synchronise</string>
// Sync
<string name="next">NEXT</string>
<string name="back">BACK</string>
<string name="accept">ACCEPT</string>
<string name="reject">REJECT</string>
<string name="done">DONE</string>
</resources>