mirror of
https://github.com/sudoxnym/habitica-android.git
synced 2026-04-14 19:56:32 +00:00
Merge pull request #595 from TheHollidayInn/invites-qr-code
Invites qr code
This commit is contained in:
commit
a954f481d9
19 changed files with 503 additions and 23 deletions
|
|
@ -14,7 +14,7 @@
|
|||
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
|
||||
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
|
||||
<uses-permission android:name="android.permission.INTERNET" />
|
||||
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
|
||||
|
||||
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
|
||||
<uses-permission android:name="com.android.vending.BILLING" />
|
||||
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
|
||||
|
|
@ -172,4 +172,5 @@
|
|||
</provider>
|
||||
</application>
|
||||
|
||||
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
|
||||
</manifest>
|
||||
|
|
|
|||
|
|
@ -81,6 +81,9 @@ dependencies {
|
|||
// Image Loading/Caching
|
||||
compile 'com.squareup.picasso:picasso:2.5.2'
|
||||
|
||||
//QR Code
|
||||
compile 'com.github.kenglxn.QRGen:android:2.2.0'
|
||||
|
||||
// Emojis
|
||||
compile 'com.github.viirus:emoji-lib:0.0.3.2'
|
||||
|
||||
|
|
|
|||
|
|
@ -6,16 +6,20 @@
|
|||
android:layout_height="match_parent"
|
||||
tools:context=".ui.activities.PrefsActivity">
|
||||
|
||||
<FrameLayout
|
||||
android:id="@+id/fragment_container"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
app:layout_behavior="@string/appbar_scrolling_view_behavior"
|
||||
android:layout_gravity="top|center" >
|
||||
|
||||
</FrameLayout>
|
||||
|
||||
<android.support.design.widget.CoordinatorLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
tools:context=".ui.activities.MainActivity">
|
||||
|
||||
<FrameLayout
|
||||
android:id="@+id/fragment_container"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
app:layout_behavior="@string/appbar_scrolling_view_behavior"/>
|
||||
tools:context=".ui.activities.MainActivity"
|
||||
android:layout_gravity="center_horizontal|bottom">
|
||||
|
||||
<android.support.design.widget.AppBarLayout
|
||||
android:layout_width="match_parent"
|
||||
|
|
@ -33,4 +37,5 @@
|
|||
</android.support.design.widget.AppBarLayout>
|
||||
|
||||
</android.support.design.widget.CoordinatorLayout>
|
||||
|
||||
</FrameLayout>
|
||||
|
|
@ -34,7 +34,6 @@
|
|||
android:layout_height="match_parent"
|
||||
android:scrollbarSize="3dp"
|
||||
android:scrollbarThumbVertical="@color/md_grey_500"
|
||||
|
||||
android:scrollbars="vertical">
|
||||
|
||||
<LinearLayout
|
||||
|
|
@ -42,6 +41,23 @@
|
|||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical">
|
||||
|
||||
<android.support.v7.widget.CardView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
style="@style/CardView.Default"
|
||||
android:id="@+id/qrWrapper"
|
||||
>
|
||||
|
||||
<LinearLayout
|
||||
android:orientation="vertical"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
style="@style/CardContent">
|
||||
|
||||
<include layout="@layout/qr_code" />
|
||||
</LinearLayout>
|
||||
</android.support.v7.widget.CardView>
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@
|
|||
android:layout_height="wrap_content"
|
||||
android:layout_margin="@dimen/row_padding"
|
||||
style="@style/CardTitle"/>
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/invitationWrapper"
|
||||
android:layout_width="match_parent"
|
||||
|
|
@ -20,6 +21,7 @@
|
|||
android:clickable="false"
|
||||
android:layout_marginLeft="@dimen/row_padding"
|
||||
android:layout_marginRight="@dimen/row_padding" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/addInviteButton"
|
||||
android:layout_width="wrap_content"
|
||||
|
|
@ -27,5 +29,15 @@
|
|||
android:layout_gravity="right"
|
||||
android:text="@string/add_invites"
|
||||
android:layout_margin="@dimen/row_padding" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/InviteByQR"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Scan a QR Code"
|
||||
style="@style/Widget.AppCompat.Button.Colored"
|
||||
android:layout_margin="20dp"
|
||||
android:layout_gravity="center_horizontal|bottom"
|
||||
/>
|
||||
</LinearLayout>
|
||||
</ScrollView>
|
||||
59
Habitica/res/layout/qr_code.xml
Normal file
59
Habitica/res/layout/qr_code.xml
Normal file
|
|
@ -0,0 +1,59 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:orientation="vertical"
|
||||
android:id="@+id/qrLayout"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/qr_section_title"
|
||||
style="@style/SectionTitle"
|
||||
android:layout_gravity="center"
|
||||
/>
|
||||
|
||||
<FrameLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:orientation="vertical"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="300dp"
|
||||
android:id="@+id/qrCodeWrapper">
|
||||
|
||||
<ImageView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="match_parent"
|
||||
android:id="@+id/QRImageView"
|
||||
android:layout_gravity="center" />
|
||||
|
||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:orientation="vertical"
|
||||
android:layout_width="60dp"
|
||||
android:layout_height="60dp"
|
||||
android:layout_gravity="center"
|
||||
android:background="@color/transparent"
|
||||
android:clipChildren="true"
|
||||
android:padding="0dp"
|
||||
>
|
||||
<com.habitrpg.android.habitica.ui.AvatarView
|
||||
android:id="@+id/avatarView"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_centerHorizontal="true"
|
||||
android:layout_centerVertical="true"
|
||||
/>
|
||||
</RelativeLayout>
|
||||
</FrameLayout>
|
||||
|
||||
<Button
|
||||
android:id="@+id/QRDownloadButton"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Download"
|
||||
style="@style/Widget.AppCompat.Button.Colored"
|
||||
android:layout_margin="20dp"
|
||||
android:layout_gravity="center_horizontal|bottom"
|
||||
/>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
20
Habitica/res/layout/qr_dialogue.xml
Normal file
20
Habitica/res/layout/qr_dialogue.xml
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content" >
|
||||
|
||||
<include
|
||||
layout="@layout/qr_code" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/dialogButtonOK"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Ok"
|
||||
android:layout_marginTop="5dp"
|
||||
android:layout_marginRight="5dp"
|
||||
android:layout_centerHorizontal="true"
|
||||
android:layout_below="@+id/qrLayout"
|
||||
/>
|
||||
|
||||
</RelativeLayout>
|
||||
|
|
@ -15,6 +15,7 @@
|
|||
<string name="SP_userID_summary">Your User ID</string>
|
||||
<string name="SP_APIToken_title">API Token</string>
|
||||
<string name="SP_APIToken_summary">Your API Token</string>
|
||||
<string name="SP_user_qr_code">Your QR Code</string>
|
||||
<string name="PS_contact_title">Contact me</string>
|
||||
<string name="unknown_error">An error happened…</string>
|
||||
<string name="pref_account_header">Account</string>
|
||||
|
|
@ -377,4 +378,12 @@ To start, which parts of your life do you want to improve?</string>
|
|||
<string name="gold_plural">gold</string>
|
||||
<string name="chat_message_copied">Message copied to Clipboard</string>
|
||||
<string name="copy_chat_message">Copy to clipboard</string>
|
||||
|
||||
<!-- QR Strings -->
|
||||
<string name="qr_section_title">Have someone invite you with this QR Code</string>
|
||||
<string name="qr_album_name">habitica</string>
|
||||
<string name="qr_file_name"> habitrpg-qr-code.jpg</string>
|
||||
<string name="qr_save_message">QR code saved at </string>
|
||||
<string name="qr_dialogue_title">Your QR Code</string>
|
||||
|
||||
</resources>
|
||||
|
|
|
|||
|
|
@ -46,6 +46,14 @@
|
|||
android:shouldDisableView="false"
|
||||
android:summary="@string/SP_APIToken_summary"/>
|
||||
|
||||
<Preference
|
||||
android:key="@string/SP_user_qr_code"
|
||||
android:title="@string/SP_user_qr_code"
|
||||
android:selectable="true"
|
||||
android:persistent="false"
|
||||
android:shouldDisableView="false"
|
||||
android:summary="@string/SP_user_qr_code"/>
|
||||
|
||||
</PreferenceCategory>
|
||||
|
||||
</PreferenceScreen>
|
||||
|
|
|
|||
|
|
@ -0,0 +1,176 @@
|
|||
package com.habitrpg.android.habitica.helpers;
|
||||
|
||||
import android.app.Dialog;
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.graphics.Bitmap;
|
||||
import android.media.Image;
|
||||
import android.os.Environment;
|
||||
import android.support.v7.preference.PreferenceManager;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
import android.widget.FrameLayout;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.habitrpg.android.habitica.R;
|
||||
import com.habitrpg.android.habitica.ui.AvatarView;
|
||||
import com.magicmicky.habitrpgwrapper.lib.models.HabitRPGUser;
|
||||
import com.mikepenz.materialize.color.Material;
|
||||
import com.raizlabs.android.dbflow.runtime.transaction.BaseTransaction;
|
||||
import com.raizlabs.android.dbflow.runtime.transaction.TransactionListener;
|
||||
import com.raizlabs.android.dbflow.sql.builder.Condition;
|
||||
import com.raizlabs.android.dbflow.sql.language.Select;
|
||||
|
||||
import net.glxn.qrgen.android.QRCode;
|
||||
import net.glxn.qrgen.core.image.ImageType;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* Created by keithholliday on 8/12/16.
|
||||
*/
|
||||
public class QrCodeManager {
|
||||
|
||||
//@TODO: Allow users to set other content
|
||||
private String content;
|
||||
private String userId;
|
||||
private Context context;
|
||||
private String qrProfileUrl = "https://habitica.com/qr-code/user/";
|
||||
|
||||
private ImageView qrCodeImageView;
|
||||
private Button qrCodeDownloadButton;
|
||||
private AvatarView avatarView;
|
||||
private FrameLayout qrCodeWrapper;
|
||||
|
||||
private String albumnName;
|
||||
private String fileName;
|
||||
private String saveMessage;
|
||||
|
||||
private TransactionListener<HabitRPGUser> userTransactionListener = new TransactionListener<HabitRPGUser>() {
|
||||
@Override
|
||||
public void onResultReceived(HabitRPGUser habitRPGUser) {
|
||||
QrCodeManager.this.avatarView.setUser(habitRPGUser);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onReady(BaseTransaction<HabitRPGUser> baseTransaction) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasResult(BaseTransaction<HabitRPGUser> baseTransaction, HabitRPGUser habitRPGUser) {
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
public QrCodeManager(Context context) {
|
||||
this.context = context;
|
||||
|
||||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this.context);
|
||||
String userId = prefs.getString(this.context.getString(R.string.SP_userID), "");
|
||||
|
||||
this.albumnName = this.context.getString(R.string.qr_album_name);
|
||||
this.fileName = this.context.getString(R.string.qr_file_name);
|
||||
this.saveMessage = this.context.getString(R.string.qr_save_message);
|
||||
|
||||
this.content = this.qrProfileUrl + userId;
|
||||
this.userId = userId;
|
||||
}
|
||||
|
||||
public void setUpView(LinearLayout qrLayout) {
|
||||
this.qrCodeImageView = (ImageView) qrLayout.findViewById(R.id.QRImageView);
|
||||
this.qrCodeDownloadButton = (Button) qrLayout.findViewById(R.id.QRDownloadButton);
|
||||
this.avatarView = (AvatarView) qrLayout.findViewById(R.id.avatarView);
|
||||
this.avatarView.configureView(false, false, false);
|
||||
this.qrCodeWrapper = (FrameLayout) qrLayout.findViewById(R.id.qrCodeWrapper);
|
||||
|
||||
//@TODO: Move to user helper/model
|
||||
new Select()
|
||||
.from(HabitRPGUser.class)
|
||||
.where(Condition.column("id")
|
||||
.eq(userId))
|
||||
.async()
|
||||
.querySingle(userTransactionListener);
|
||||
|
||||
this.displayQrCode();
|
||||
this.setDownloadQr();
|
||||
}
|
||||
|
||||
public void displayQrCode() {
|
||||
if (qrCodeImageView == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
Bitmap myBitmap = QRCode.from(this.content).withColor(0xFF432874, 0xFFFFFFFF).withSize(400, 400).bitmap();
|
||||
qrCodeImageView.setImageBitmap(myBitmap);
|
||||
}
|
||||
|
||||
public void setDownloadQr() {
|
||||
if (qrCodeDownloadButton == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
qrCodeDownloadButton.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
File dir = getAlbumStorageDir(context, albumnName);
|
||||
dir.mkdirs();
|
||||
|
||||
File pathToQRCode = new File(dir, fileName);
|
||||
try {
|
||||
pathToQRCode.createNewFile();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
try {
|
||||
FileOutputStream outputStream = new FileOutputStream(pathToQRCode);
|
||||
qrCodeWrapper.setDrawingCacheEnabled(true);
|
||||
Bitmap b = qrCodeWrapper.getDrawingCache();
|
||||
b.compress(Bitmap.CompressFormat.JPEG, 95, outputStream);
|
||||
|
||||
outputStream.close();
|
||||
|
||||
Toast.makeText(context, saveMessage + pathToQRCode.getPath(),
|
||||
Toast.LENGTH_LONG).show();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private File getAlbumStorageDir(Context context, String albumName) {
|
||||
// Get the directory for the app's private pictures directory.
|
||||
File file = new File(context.getExternalFilesDir(
|
||||
Environment.DIRECTORY_PICTURES), albumName);
|
||||
file.mkdirs();
|
||||
return file;
|
||||
}
|
||||
|
||||
public void showDialogue() {
|
||||
final Dialog dialog = new Dialog(context);
|
||||
dialog.setContentView(R.layout.qr_dialogue);
|
||||
dialog.setTitle(R.string.qr_dialogue_title);
|
||||
|
||||
LinearLayout qrLayout = (LinearLayout) dialog.findViewById(R.id.qrLayout);
|
||||
this.setUpView(qrLayout);
|
||||
Button dialogButton = (Button) dialog.findViewById(R.id.dialogButtonOK);
|
||||
|
||||
dialogButton.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
dialog.dismiss();
|
||||
}
|
||||
});
|
||||
|
||||
dialog.show();
|
||||
}
|
||||
}
|
||||
|
|
@ -91,6 +91,12 @@ public class AvatarView extends View {
|
|||
isOrphan = true;
|
||||
}
|
||||
|
||||
public void configureView(boolean showBackground, boolean showMount, boolean showPet) {
|
||||
this.showBackground = showBackground;
|
||||
this.showMount = showMount;
|
||||
this.showPet = showPet;
|
||||
}
|
||||
|
||||
private void init(AttributeSet attrs, int defStyle) {
|
||||
// Load attributes
|
||||
final TypedArray a = getContext().obtainStyledAttributes(
|
||||
|
|
|
|||
|
|
@ -34,6 +34,8 @@ import com.habitrpg.android.habitica.events.commands.SellItemCommand;
|
|||
import com.habitrpg.android.habitica.events.commands.UnlockPathCommand;
|
||||
import com.habitrpg.android.habitica.events.commands.UpdateUserCommand;
|
||||
import com.habitrpg.android.habitica.helpers.notifications.PushNotificationManager;
|
||||
import com.habitrpg.android.habitica.prefs.scanner.IntentIntegrator;
|
||||
import com.habitrpg.android.habitica.prefs.scanner.IntentResult;
|
||||
import com.habitrpg.android.habitica.ui.AvatarView;
|
||||
import com.habitrpg.android.habitica.ui.AvatarWithBarsViewModel;
|
||||
import com.habitrpg.android.habitica.ui.TutorialView;
|
||||
|
|
@ -126,6 +128,7 @@ import android.view.View;
|
|||
import android.widget.FrameLayout;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
|
|
|
|||
|
|
@ -1,21 +1,39 @@
|
|||
package com.habitrpg.android.habitica.ui.activities;
|
||||
|
||||
import com.habitrpg.android.habitica.APIHelper;
|
||||
import com.habitrpg.android.habitica.HostConfig;
|
||||
import com.habitrpg.android.habitica.R;
|
||||
import com.habitrpg.android.habitica.callbacks.HabitRPGUserCallback;
|
||||
import com.habitrpg.android.habitica.components.AppComponent;
|
||||
import com.habitrpg.android.habitica.prefs.scanner.IntentIntegrator;
|
||||
import com.habitrpg.android.habitica.prefs.scanner.IntentResult;
|
||||
import com.habitrpg.android.habitica.ui.fragments.social.party.PartyInviteFragment;
|
||||
import com.magicmicky.habitrpgwrapper.lib.models.HabitRPGUser;
|
||||
import com.raizlabs.android.dbflow.runtime.transaction.BaseTransaction;
|
||||
import com.raizlabs.android.dbflow.runtime.transaction.TransactionListener;
|
||||
import com.raizlabs.android.dbflow.sql.builder.Condition;
|
||||
import com.raizlabs.android.dbflow.sql.language.Select;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Intent;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.support.design.widget.TabLayout;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.support.v4.app.FragmentPagerAdapter;
|
||||
import android.support.v4.view.ViewPager;
|
||||
import android.util.Log;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
import android.widget.Toast;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import butterknife.BindView;
|
||||
|
||||
|
|
@ -25,6 +43,16 @@ public class PartyInviteActivity extends BaseActivity {
|
|||
public static final String USER_IDS_KEY = "userIDs";
|
||||
public static final String IS_EMAIL_KEY = "isEmail";
|
||||
public static final String EMAILS_KEY = "emails";
|
||||
|
||||
private HabitRPGUser user;
|
||||
private String userIdToInvite;
|
||||
|
||||
@Inject
|
||||
APIHelper apiHelper;
|
||||
|
||||
@Inject
|
||||
protected HostConfig hostConfig;
|
||||
|
||||
@BindView(R.id.tab_layout)
|
||||
TabLayout tabLayout;
|
||||
|
||||
|
|
@ -33,6 +61,23 @@ public class PartyInviteActivity extends BaseActivity {
|
|||
|
||||
List<PartyInviteFragment> fragments = new ArrayList<>();
|
||||
|
||||
private TransactionListener<HabitRPGUser> userTransactionListener = new TransactionListener<HabitRPGUser>() {
|
||||
@Override
|
||||
public void onResultReceived(HabitRPGUser habitRPGUser) {
|
||||
handleUserRecieved(habitRPGUser);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onReady(BaseTransaction<HabitRPGUser> baseTransaction) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasResult(BaseTransaction<HabitRPGUser> baseTransaction, HabitRPGUser habitRPGUser) {
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
@Override
|
||||
protected int getLayoutResId() {
|
||||
return R.layout.activity_party_invite;
|
||||
|
|
@ -129,4 +174,46 @@ public class PartyInviteActivity extends BaseActivity {
|
|||
tabLayout.setupWithViewPager(viewPager);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||
super.onActivityResult(requestCode, resultCode, data);
|
||||
|
||||
IntentResult scanningResult = IntentIntegrator.parseActivityResult(requestCode, resultCode, data);
|
||||
|
||||
if (scanningResult != null && scanningResult.getContents() != null) {
|
||||
String qrCodeUrl = scanningResult.getContents();
|
||||
Uri uri = Uri.parse(qrCodeUrl);
|
||||
if (uri == null || uri.getPathSegments().size() < 3) {
|
||||
return;
|
||||
}
|
||||
userIdToInvite = uri.getPathSegments().get(2);
|
||||
|
||||
//@TODO: Move to user helper/model
|
||||
new Select().from(HabitRPGUser.class).where(Condition.column("id").eq(hostConfig.getUser())).async().querySingle(userTransactionListener);
|
||||
}
|
||||
}
|
||||
|
||||
public void handleUserRecieved(HabitRPGUser user) {
|
||||
this.user = user;
|
||||
|
||||
if (this.userIdToInvite == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
Toast toast = Toast.makeText(getApplicationContext(),
|
||||
"Invited: " + userIdToInvite, Toast.LENGTH_LONG);
|
||||
toast.show();
|
||||
|
||||
Map<String, Object> inviteData = new HashMap<>();
|
||||
List<String> invites = new ArrayList<>();
|
||||
invites.add(userIdToInvite);
|
||||
inviteData.put("uuids", invites);
|
||||
|
||||
this.apiHelper.apiService.inviteToGroup(this.user.getParty().getId(), inviteData)
|
||||
.compose(apiHelper.configureApiCallObserver())
|
||||
.subscribe(aVoid -> {
|
||||
}, throwable -> {
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,6 +15,9 @@ import android.preference.PreferenceManager;
|
|||
import android.support.v7.preference.PreferenceFragmentCompat;
|
||||
import android.support.v7.preference.PreferenceScreen;
|
||||
import android.support.v7.widget.Toolbar;
|
||||
import android.view.View;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.LinearLayout;
|
||||
|
||||
import butterknife.BindView;
|
||||
|
||||
|
|
|
|||
|
|
@ -1,19 +1,32 @@
|
|||
package com.habitrpg.android.habitica.ui.fragments.preferences;
|
||||
|
||||
import com.habitrpg.android.habitica.R;
|
||||
import com.habitrpg.android.habitica.helpers.QrCodeManager;
|
||||
|
||||
import android.content.ClipData;
|
||||
import android.content.ClipboardManager;
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.graphics.Bitmap;
|
||||
import android.support.v7.preference.Preference;
|
||||
import android.support.v7.preference.PreferenceManager;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.Toast;
|
||||
|
||||
import net.glxn.qrgen.android.QRCode;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class AccountDetailsFragment extends BasePreferencesFragment {
|
||||
|
||||
private QrCodeManager qrCodeManager;
|
||||
|
||||
@Override
|
||||
protected void setupPreferences() {
|
||||
for (Map.Entry<String, ?> preference : getPreferenceScreen().getSharedPreferences().getAll().entrySet()) {
|
||||
|
|
@ -22,15 +35,21 @@ public class AccountDetailsFragment extends BasePreferencesFragment {
|
|||
findPreference(key).setSummary(preference.getValue().toString());
|
||||
}
|
||||
}
|
||||
|
||||
qrCodeManager = new QrCodeManager(this.getContext());
|
||||
}
|
||||
|
||||
protected List<String> getAccountDetailsPreferences() {
|
||||
return Arrays.asList(getString(R.string.SP_username), getString(R.string.SP_email),
|
||||
getString(R.string.SP_APIToken), getString(R.string.SP_userID));
|
||||
getString(R.string.SP_APIToken), getString(R.string.SP_userID), getString(R.string.SP_user_qr_code));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onPreferenceTreeClick(Preference preference) {
|
||||
if (preference.getKey().equals(getString(R.string.SP_user_qr_code))) {
|
||||
qrCodeManager.showDialogue();
|
||||
}
|
||||
|
||||
ClipboardManager clipMan = (ClipboardManager) getActivity().getSystemService(Context.CLIPBOARD_SERVICE);
|
||||
clipMan.setPrimaryClip(ClipData.newPlainText(preference.getKey(), preference.getSummary()));
|
||||
Toast.makeText(getActivity(), "Copied " + preference.getKey() + " to clipboard.", Toast.LENGTH_SHORT).show();
|
||||
|
|
|
|||
|
|
@ -5,6 +5,9 @@ import com.habitrpg.android.habitica.R;
|
|||
import com.habitrpg.android.habitica.components.AppComponent;
|
||||
import com.habitrpg.android.habitica.databinding.FragmentGroupInfoBinding;
|
||||
import com.habitrpg.android.habitica.databinding.ValueBarBinding;
|
||||
import com.habitrpg.android.habitica.helpers.QrCodeManager;
|
||||
import com.habitrpg.android.habitica.prefs.scanner.IntentIntegrator;
|
||||
import com.habitrpg.android.habitica.ui.AvatarView;
|
||||
import com.habitrpg.android.habitica.ui.adapter.social.QuestCollectRecyclerViewAdapter;
|
||||
import com.habitrpg.android.habitica.ui.fragments.BaseFragment;
|
||||
import com.magicmicky.habitrpgwrapper.lib.models.Group;
|
||||
|
|
@ -13,17 +16,35 @@ import com.magicmicky.habitrpgwrapper.lib.models.inventory.QuestContent;
|
|||
|
||||
import android.app.AlertDialog;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.databinding.DataBindingUtil;
|
||||
import android.graphics.Bitmap;
|
||||
import android.os.Bundle;
|
||||
import android.os.Environment;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v4.content.ContextCompat;
|
||||
import android.support.v7.preference.PreferenceManager;
|
||||
import android.support.v7.widget.CardView;
|
||||
import android.support.v7.widget.LinearLayoutManager;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.Button;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import net.glxn.qrgen.android.QRCode;
|
||||
import net.glxn.qrgen.core.image.ImageType;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
|
|
@ -35,12 +56,22 @@ public class GroupInformationFragment extends BaseFragment {
|
|||
|
||||
|
||||
FragmentGroupInfoBinding viewBinding;
|
||||
|
||||
@Inject
|
||||
APIHelper apiHelper;
|
||||
|
||||
@BindView(R.id.questMemberView)
|
||||
LinearLayout questMemberView;
|
||||
|
||||
@BindView(R.id.collectionStats)
|
||||
RecyclerView collectionStats;
|
||||
|
||||
@BindView(R.id.qrLayout)
|
||||
LinearLayout qrLayout;
|
||||
|
||||
@BindView(R.id.qrWrapper)
|
||||
CardView qrWrapper;
|
||||
|
||||
private View view;
|
||||
private Group group;
|
||||
private HabitRPGUser user;
|
||||
|
|
@ -55,7 +86,6 @@ public class GroupInformationFragment extends BaseFragment {
|
|||
}
|
||||
|
||||
public static GroupInformationFragment newInstance(Group group, HabitRPGUser user) {
|
||||
|
||||
Bundle args = new Bundle();
|
||||
|
||||
GroupInformationFragment fragment = new GroupInformationFragment();
|
||||
|
|
@ -74,6 +104,7 @@ public class GroupInformationFragment extends BaseFragment {
|
|||
|
||||
viewBinding = DataBindingUtil.bind(view);
|
||||
viewBinding.setHideParticipantCard(false);
|
||||
|
||||
if (user != null) {
|
||||
viewBinding.setUser(user);
|
||||
}
|
||||
|
|
@ -89,6 +120,15 @@ public class GroupInformationFragment extends BaseFragment {
|
|||
bossHpBar = DataBindingUtil.bind(view.findViewById(R.id.bossHpBar));
|
||||
bossRageBar = DataBindingUtil.bind(view.findViewById(R.id.bossRageBar));
|
||||
|
||||
if (this.group == null) {
|
||||
QrCodeManager qrCodeManager = new QrCodeManager(this.getContext());
|
||||
qrCodeManager.setUpView(qrLayout);
|
||||
}
|
||||
|
||||
if (user != null && user.getParty().getId() != null) {
|
||||
((ViewGroup) qrWrapper.getParent()).removeView(qrWrapper);
|
||||
}
|
||||
|
||||
return view;
|
||||
}
|
||||
|
||||
|
|
@ -291,5 +331,4 @@ public class GroupInformationFragment extends BaseFragment {
|
|||
});
|
||||
builder.show();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -84,15 +84,15 @@ public class PartyFragment extends BaseMainFragment {
|
|||
}, throwable -> {
|
||||
});
|
||||
} else {
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(activity)
|
||||
.setMessage(activity.getString(R.string.no_party_message))
|
||||
.setNeutralButton(android.R.string.ok, (dialog, which) -> {
|
||||
activity.getSupportFragmentManager().popBackStackImmediate();
|
||||
});
|
||||
builder.show();
|
||||
if (tabLayout != null) {
|
||||
tabLayout.removeAllTabs();
|
||||
}
|
||||
// AlertDialog.Builder builder = new AlertDialog.Builder(activity)
|
||||
// .setMessage(activity.getString(R.string.no_party_message))
|
||||
// .setNeutralButton(android.R.string.ok, (dialog, which) -> {
|
||||
// activity.getSupportFragmentManager().popBackStackImmediate();
|
||||
// });
|
||||
// builder.show();
|
||||
// if (tabLayout != null) {
|
||||
// tabLayout.removeAllTabs();
|
||||
// }
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ package com.habitrpg.android.habitica.ui.fragments.social.party;
|
|||
|
||||
import com.habitrpg.android.habitica.R;
|
||||
import com.habitrpg.android.habitica.components.AppComponent;
|
||||
import com.habitrpg.android.habitica.prefs.scanner.IntentIntegrator;
|
||||
import com.habitrpg.android.habitica.ui.fragments.BaseFragment;
|
||||
|
||||
import android.os.Bundle;
|
||||
|
|
@ -57,6 +58,7 @@ public class PartyInviteFragment extends BaseFragment {
|
|||
@OnClick(R.id.addInviteButton)
|
||||
public void addInviteField() {
|
||||
EditText editText = new EditText(getContext());
|
||||
|
||||
if (isEmailInvite) {
|
||||
editText.setHint(R.string.email);
|
||||
editText.setInputType(InputType.TYPE_TEXT_VARIATION_EMAIL_ADDRESS);
|
||||
|
|
@ -66,6 +68,12 @@ public class PartyInviteFragment extends BaseFragment {
|
|||
invitationWrapper.addView(editText);
|
||||
}
|
||||
|
||||
@OnClick(R.id.InviteByQR)
|
||||
public void startQRInvite() {
|
||||
IntentIntegrator scanIntegrator = new IntentIntegrator(getActivity());
|
||||
scanIntegrator.initiateScan();
|
||||
}
|
||||
|
||||
public String[] getValues() {
|
||||
List<String> values = new ArrayList<>();
|
||||
for (int i = 0; i < invitationWrapper.getChildCount(); i++) {
|
||||
|
|
|
|||
|
|
@ -316,7 +316,10 @@ public class TaskAlarmManagerTest {
|
|||
|
||||
Assert.assertNotNull(alarmId);
|
||||
Assert.assertEquals(true, alarmUp);
|
||||
Assert.assertEquals(currentDayOfTheWeek + everyXDay, newReminderTime.get(Calendar.DAY_OF_WEEK));
|
||||
|
||||
int expectedDay = (currentDayOfTheWeek + everyXDay) % 7;
|
||||
|
||||
Assert.assertEquals(expectedDay, newReminderTime.get(Calendar.DAY_OF_WEEK));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -358,6 +361,9 @@ public class TaskAlarmManagerTest {
|
|||
|
||||
Assert.assertNotNull(alarmId);
|
||||
Assert.assertEquals(true, alarmUp);
|
||||
Assert.assertEquals(currentDayOfTheWeek + everyXDay, newReminderTime.get(Calendar.DAY_OF_WEEK));
|
||||
|
||||
int expectedDay = (currentDayOfTheWeek + everyXDay) % 7;
|
||||
|
||||
Assert.assertEquals(expectedDay, newReminderTime.get(Calendar.DAY_OF_WEEK));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue