Readability & layout

This commit is contained in:
Alessandro Ferro 2022-10-25 22:33:28 +02:00
parent 3e162b88ce
commit c58fd719b3
3 changed files with 6 additions and 7 deletions

View File

@ -108,7 +108,8 @@ public class WhitelistContactsActivity extends AppCompatActivity {
private void contactSelected(String phoneNo){ private void contactSelected(String phoneNo){
// We'll replace parenthesis, dashes and whitespaces to obtain a valid phone number // We'll replace parenthesis, dashes and whitespaces to obtain a valid phone number
phoneNo = phoneNo.replaceAll("[-()\\s]", ""); phoneNo = phoneNo.replaceAll("[-()\\s]", "");
if(whitelistDbHandler.isContactPresent(phoneNo)){
if(contacts.contains(phoneNo)){
Toast.makeText(this, "Contact already in the list", Toast.LENGTH_SHORT).show(); Toast.makeText(this, "Contact already in the list", Toast.LENGTH_SHORT).show();
return; return;
} }

View File

@ -54,11 +54,10 @@ public class WhitelistDbHandler extends SQLiteOpenHelper {
} }
public ArrayList<String> getAllContacts() { public ArrayList<String> getAllContacts() {
ArrayList<String> array_list = new ArrayList<String>(); ArrayList<String> array_list = new ArrayList<>();
//hp = new HashMap();
SQLiteDatabase db = this.getReadableDatabase(); SQLiteDatabase db = this.getReadableDatabase();
Cursor cursor = db.rawQuery( "select * from " + TABLE_CONTACTS, null ); String query = String.format("SELECT %s FROM %s", KEY_PH_NO, TABLE_CONTACTS);
Cursor cursor = db.rawQuery( query, null );
cursor.moveToFirst(); cursor.moveToFirst();
int columnIndex = cursor.getColumnIndex(KEY_PH_NO); int columnIndex = cursor.getColumnIndex(KEY_PH_NO);
@ -102,5 +101,4 @@ public class WhitelistDbHandler extends SQLiteOpenHelper {
cursor.close(); cursor.close();
return count > 0; return count > 0;
} }
} }

View File

@ -100,7 +100,7 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginStart="10dp" android:layout_marginStart="10dp"
android:layout_marginEnd="10dp" android:layout_marginEnd="10dp"
android:text="Add contacts"/> android:text="Whitelist contacts"/>
<View <View
android:layout_width="match_parent" android:layout_width="match_parent"