mirror of
https://github.com/ArcaneChat/android.git
synced 2026-07-03 14:05:24 +02:00
Tackle null pointer exceptions
This commit is contained in:
@@ -1,6 +1,26 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:orientation="vertical" android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/qrImage"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="0dp"
|
||||
android:layout_weight="1"
|
||||
android:contentDescription="@string/qrscan_title" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/qrShowHint"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginBottom="16dp"
|
||||
android:layout_marginEnd="8dp"
|
||||
android:layout_marginStart="8dp"
|
||||
android:text=""
|
||||
android:textAlignment="center"
|
||||
android:textAppearance="@style/TextAppearance.AppCompat"
|
||||
android:textSize="16sp" />
|
||||
|
||||
</LinearLayout>
|
||||
@@ -87,13 +87,13 @@ public class QrActivity extends AppCompatActivity {
|
||||
super(fragmentManager);
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public Fragment getItem(int position) {
|
||||
//int tabId = tabs.get(position); // TODO wrong solution
|
||||
Fragment fragment;
|
||||
Bundle args = new Bundle();
|
||||
|
||||
switch (position) { // TODO was tabId
|
||||
switch (position) {
|
||||
case 0:
|
||||
fragment = new QrScanFragment();
|
||||
break;
|
||||
|
||||
@@ -32,7 +32,7 @@ public class QrScanFragment extends Fragment {
|
||||
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||
View view = inflater.inflate(R.layout.qr_scan_fragment, container, false);
|
||||
|
||||
barcodeScannerView = getActivity().findViewById(R.id.zxing_barcode_scanner);
|
||||
barcodeScannerView = view.findViewById(R.id.zxing_barcode_scanner);
|
||||
barcodeScannerView.setStatusText(getString(R.string.qrscan_hint) + "\n ");
|
||||
|
||||
|
||||
|
||||
@@ -61,55 +61,6 @@ public class QrShowFragment extends Fragment implements DcEventCenter.DcEventDel
|
||||
super.onCreate(bundle);
|
||||
|
||||
getActivity().getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); // keeping the screen on also avoids falling back from IDLE to POLL
|
||||
|
||||
dcContext = DcHelper.getContext(getActivity());
|
||||
dcEventCenter = dcContext.eventCenter;
|
||||
|
||||
Bundle extras = getActivity().getIntent().getExtras();
|
||||
int chatId = 0;
|
||||
if (extras != null) {
|
||||
chatId = extras.getInt(CHAT_ID);
|
||||
}
|
||||
|
||||
errorHint = getString(R.string.qrshow_join_contact_no_connection_hint);
|
||||
|
||||
if (chatId != 0) {
|
||||
// verified-group
|
||||
String groupName = dcContext.getChat(chatId).getName();
|
||||
hint = String.format(this.getString(R.string.qrshow_join_group_hint), groupName);
|
||||
} else {
|
||||
// verify-contact
|
||||
String selfName = DcHelper.get(getActivity(), DcHelper.CONFIG_DISPLAY_NAME); // we cannot use MrContact.getDisplayName() as this would result in "Me" instead of
|
||||
String nameAndAddress;
|
||||
if (selfName.isEmpty()) {
|
||||
selfName = DcHelper.get(getActivity(), DcHelper.CONFIG_ADDRESS, "unknown");
|
||||
nameAndAddress = selfName;
|
||||
} else {
|
||||
nameAndAddress = String.format("%s (%s)", selfName, DcHelper.get(getActivity(), DcHelper.CONFIG_ADDRESS));
|
||||
}
|
||||
hint = String.format(this.getString(R.string.qrshow_join_contact_hint), nameAndAddress);
|
||||
}
|
||||
hintBelowQr = getActivity().findViewById(R.id.qrShowHint);
|
||||
setHintText();
|
||||
|
||||
numJoiners = 0;
|
||||
|
||||
ImageView imageView = getActivity().findViewById(R.id.qrImage);
|
||||
try {
|
||||
Bitmap bitmap = encodeAsBitmap(dcContext.getSecurejoinQr(chatId));
|
||||
imageView.setImageBitmap(bitmap);
|
||||
} catch (WriterException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
dcEventCenter.addObserver(DcContext.DC_EVENT_SECUREJOIN_INVITER_PROGRESS, this);
|
||||
broadcastReceiver = new BroadcastReceiver() {
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
setHintText();
|
||||
}
|
||||
};
|
||||
getActivity().registerReceiver(broadcastReceiver, new IntentFilter(android.net.ConnectivityManager.CONNECTIVITY_ACTION));
|
||||
}
|
||||
|
||||
private void setHintText() {
|
||||
@@ -129,8 +80,8 @@ public class QrShowFragment extends Fragment implements DcEventCenter.DcEventDel
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
super.onDestroy();
|
||||
public void onDestroyView() {
|
||||
super.onDestroyView();
|
||||
dcEventCenter.removeObservers(this);
|
||||
getActivity().unregisterReceiver(broadcastReceiver);
|
||||
}
|
||||
@@ -208,6 +159,55 @@ public class QrShowFragment extends Fragment implements DcEventCenter.DcEventDel
|
||||
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||
View view = inflater.inflate(R.layout.qr_show_fragment, container, false);
|
||||
|
||||
dcContext = DcHelper.getContext(getActivity());
|
||||
dcEventCenter = dcContext.eventCenter;
|
||||
|
||||
Bundle extras = getActivity().getIntent().getExtras();
|
||||
int chatId = 0;
|
||||
if (extras != null) {
|
||||
chatId = extras.getInt(CHAT_ID);
|
||||
}
|
||||
|
||||
errorHint = getString(R.string.qrshow_join_contact_no_connection_hint);
|
||||
|
||||
if (chatId != 0) {
|
||||
// verified-group
|
||||
String groupName = dcContext.getChat(chatId).getName();
|
||||
hint = String.format(this.getString(R.string.qrshow_join_group_hint), groupName);
|
||||
} else {
|
||||
// verify-contact
|
||||
String selfName = DcHelper.get(getActivity(), DcHelper.CONFIG_DISPLAY_NAME); // we cannot use MrContact.getDisplayName() as this would result in "Me" instead of
|
||||
String nameAndAddress;
|
||||
if (selfName.isEmpty()) {
|
||||
selfName = DcHelper.get(getActivity(), DcHelper.CONFIG_ADDRESS, "unknown");
|
||||
nameAndAddress = selfName;
|
||||
} else {
|
||||
nameAndAddress = String.format("%s (%s)", selfName, DcHelper.get(getActivity(), DcHelper.CONFIG_ADDRESS));
|
||||
}
|
||||
hint = String.format(this.getString(R.string.qrshow_join_contact_hint), nameAndAddress);
|
||||
}
|
||||
hintBelowQr = view.findViewById(R.id.qrShowHint);
|
||||
setHintText();
|
||||
|
||||
dcEventCenter.addObserver(DcContext.DC_EVENT_SECUREJOIN_INVITER_PROGRESS, this);
|
||||
broadcastReceiver = new BroadcastReceiver() {
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
setHintText();
|
||||
}
|
||||
};
|
||||
getActivity().registerReceiver(broadcastReceiver, new IntentFilter(android.net.ConnectivityManager.CONNECTIVITY_ACTION));
|
||||
|
||||
numJoiners = 0;
|
||||
|
||||
ImageView imageView = view.findViewById(R.id.qrImage);
|
||||
try {
|
||||
Bitmap bitmap = encodeAsBitmap(dcContext.getSecurejoinQr(chatId));
|
||||
imageView.setImageBitmap(bitmap);
|
||||
} catch (WriterException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return view;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user