Skip to content

Commit

Permalink
added search feature in activity_settings.xml, improved the activity_…
Browse files Browse the repository at this point in the history
…main.xml
  • Loading branch information
salman660 committed Sep 15, 2023
1 parent 14acdee commit 3776222
Show file tree
Hide file tree
Showing 10 changed files with 190 additions and 35 deletions.
1 change: 1 addition & 0 deletions .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

33 changes: 30 additions & 3 deletions app/src/main/java/com/apptic/namaztimings/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -261,10 +261,38 @@ private void stopContinuousScrolling() {
}

private String getCurrentPrayerName() {
Coordinates coordinates = new Coordinates(29.3544, 71.6911); // Replace with your coordinates
// Get the saved time zone from SharedPreferences
SharedPreferences sharedPreferences = getSharedPreferences("MyPrefs", MODE_PRIVATE);
String savedTimeZone = sharedPreferences.getString("SelectedTimeZone", "");

// Get the saved latitude and longitude from SharedPreferences
String savedLatitude = sharedPreferences.getString("SelectedLatitude", "");
String savedLongitude = sharedPreferences.getString("SelectedLongitude", "");

// Set the time zone for the formatter
SimpleDateFormat formatter = new SimpleDateFormat("hh:mm a");
if (!savedTimeZone.isEmpty()) {
formatter.setTimeZone(TimeZone.getTimeZone(savedTimeZone));
} else {
// Set a default time zone (e.g., "Asia/Karachi") if the saved time zone is empty
formatter.setTimeZone(TimeZone.getTimeZone("Asia/Karachi"));
}

double latitude, longitude;

if (!savedLatitude.isEmpty() && !savedLongitude.isEmpty()) {
// Use the saved coordinates if available
latitude = Double.parseDouble(savedLatitude);
longitude = Double.parseDouble(savedLongitude);
} else {
// Use dummy coordinates if saved coordinates are not available
latitude = 0.0; // Replace with your dummy latitude
longitude = 0.0; // Replace with your dummy longitude
}

Coordinates coordinates = new Coordinates(latitude, longitude);
DateComponents dateComponents = DateComponents.from(new Date());
CalculationMethod calculationMethod = CalculationMethod.KARACHI;
HighLatitudeRule highLatitudeRule = HighLatitudeRule.MIDDLE_OF_THE_NIGHT;

PrayerTimes prayerTimes = new PrayerTimes(coordinates, dateComponents, calculationMethod.getParameters());

Expand Down Expand Up @@ -304,7 +332,6 @@ private String getCurrentPrayerName() {




private void updateCurrentTime() {
SimpleDateFormat dateFormat = new SimpleDateFormat("hh:mm a", Locale.getDefault());
String currentTime = dateFormat.format(new Date());
Expand Down
52 changes: 49 additions & 3 deletions app/src/main/java/com/apptic/namaztimings/TimeZoneSettings.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.Spinner;
import android.widget.TextView;
import android.widget.Toast;

import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.AppCompatSpinner;
Expand All @@ -31,13 +32,18 @@ public class TimeZoneSettings extends AppCompatActivity {
private AppCompatSpinner timeZoneSpinner;
private ImageView backIcon;
private TextView selected_time_zone_txt;

private EditText searchbox;
private SharedPreferences sharedPreferences;



@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_time_zone_settings);
setContentView(R.layout.activity_settings);

searchbox = findViewById(R.id.searchbox);
timeZoneSpinner = findViewById(R.id.timeZoneSpinner);
backIcon = findViewById(R.id.backIcon);
selected_time_zone_txt = findViewById(R.id.selected_time_zone_txt);
Expand All @@ -62,6 +68,15 @@ public void onClick(View v) {
}
});

// Add an OnClickListener to the selected_time_zone_txt TextView
searchbox.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// Open the timezone spinner
selected_time_zone_txt.performClick();
}
});


// Extract and set the list of time zones defined in coordinates.xml
List<String> definedTimeZones = extractDefinedTimeZones();
Expand All @@ -85,6 +100,37 @@ public void onClick(View v) {
timeZoneSpinner.setSelection(0);
}

// Add a TextWatcher to the searchbox EditText
searchbox.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
// Not needed for this implementation
}

@Override
public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
// Handle text changes here
String searchText = charSequence.toString().toLowerCase();
List<String> filteredTimeZones = new ArrayList<>();

for (String timeZone : definedTimeZones) {
if (timeZone.toLowerCase().contains(searchText)) {
filteredTimeZones.add(timeZone);
}
}

// Update the adapter with the filtered list
adapter.clear();
adapter.addAll(filteredTimeZones);
adapter.notifyDataSetChanged();
}

@Override
public void afterTextChanged(Editable editable) {
// Not needed for this implementation
}
});

// Handle item selection in the Spinner
timeZoneSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
Expand Down
39 changes: 39 additions & 0 deletions app/src/main/res/drawable/search_pixelated_icon.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:pathData="M11.12,6.3h1.76V4.54H7.59V6.3Z"
android:fillColor="#df0000"/>
<path
android:pathData="M14.64,8.07l0,-1.77l-1.76,0l0,1.77l1.76,0z"
android:fillColor="#df0000"/>
<path
android:pathData="M14.64,15.12l0,1.76l1.77,0l0,-1.76l-1.77,0z"
android:fillColor="#df0000"/>
<path
android:pathData="M12.88,13.35l0,1.77l1.76,0l0,-1.77l-1.76,0z"
android:fillColor="#df0000"/>
<path
android:pathData="M14.64,11.59v1.76h1.77V8.07H14.64v3.52Z"
android:fillColor="#df0000"/>
<path
android:pathData="M7.59,6.3l-1.76,0l0,1.77l1.76,0l0,-1.77z"
android:fillColor="#df0000"/>
<path
android:pathData="M16.41,16.88l0,1.76l1.76,0l0,-1.76l-1.76,0z"
android:fillColor="#df0000"/>
<path
android:pathData="M18.17,18.64l0,1.76l1.76,0l0,-1.76l-1.76,0z"
android:fillColor="#df0000"/>
<path
android:pathData="M9.36,15.12H7.59v1.76h5.29V15.12Z"
android:fillColor="#df0000"/>
<path
android:pathData="M5.83,9.83V8.07H4.07v5.28H5.83V9.83Z"
android:fillColor="#df0000"/>
<path
android:pathData="M5.83,13.35l0,1.77l1.76,0l0,-1.77l-1.76,0z"
android:fillColor="#df0000"/>
</vector>
66 changes: 44 additions & 22 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,66 +11,88 @@
android:id="@+id/topLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="12dp"
android:layout_marginBottom="10dp"
android:orientation="vertical"
android:layout_gravity="center_horizontal">
android:orientation="vertical">

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:baselineAligned="false"
android:orientation="horizontal">

<!-- App Icon (centered) -->
<ImageView
android:id="@+id/appicon"
android:layout_width="0dp"
android:layout_height="90dp"
android:layout_weight="1"
android:layout_marginLeft="50dp"
android:layout_gravity="center"
android:layout_marginLeft="50dp"
android:layout_marginTop="16dp"
android:layout_weight="1"
app:srcCompat="@drawable/namaz_logo" />

<!-- Settings Icon (extreme right) -->
<ImageView
android:paddingTop="10dp"
android:id="@+id/settingsicon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="20dp"
android:layout_gravity="end|right"
app:srcCompat="@drawable/pixelated_settings_icon_48dp"
app:tint="@color/accent_color" />
android:layout_marginRight="20dp"
android:paddingTop="10dp"
app:srcCompat="@drawable/pixelated_settings_icon_48dp"
app:tint="@color/accent_color" />
</LinearLayout>




<TextView
android:id="@+id/textViewurdu"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAlignment="center"
android:layout_gravity="center_horizontal"
android:layout_marginTop="4dp"
android:fontFamily="@font/q_pixia"
android:text="نماز اوقات"
android:textAlignment="center"
android:textColor="@color/primary_color"
android:textSize="40sp" />

<TextView
android:id="@+id/currentPrayerName"
android:layout_width="wrap_content"
android:layout_height="41dp"
android:layout_gravity="center_horizontal"
<LinearLayout
android:layout_width="284dp"
android:layout_height="58dp"
android:layout_gravity="center"
android:background="@drawable/pixel_frame_border"
android:backgroundTint="@color/accent_color"
android:fontFamily="@font/dogicapixelbold"
android:padding="12dp"
android:text="Maghrib"
android:textAlignment="center"
android:textColor="@color/primary_color" />
android:orientation="horizontal">

<TextView
android:id="@+id/currentPrayerName"
android:layout_width="wrap_content"
android:layout_height="41dp"
android:layout_gravity="center_horizontal"
android:fontFamily="@font/dogicapixelbold"
android:padding="12dp"
android:text="Maghrib"
android:layout_weight="1"
android:textAlignment="center"
android:textColor="@color/primary_color" />

<TextView
android:id="@+id/currentPrayerending"
android:layout_width="wrap_content"
android:visibility="gone"
android:layout_height="41dp"
android:layout_gravity="center_horizontal"
android:fontFamily="@font/dogica"
android:gravity="center"
android:layout_weight="2"
android:text="Ending in 50min"
android:textAlignment="center"
android:textColor="@color/primary_color"
android:textSize="8dp" />
</LinearLayout>


<TextView
android:id="@+id/dateTextView"
Expand Down Expand Up @@ -173,7 +195,7 @@
android:id="@+id/allprayers"
android:layout_width="284dp"
android:padding="15dp"
android:layout_height="wrap_content"
android:layout_height="145dp"
android:layout_gravity="center_horizontal"
android:layout_marginBottom="10dp"
android:backgroundTint="@color/accent_color"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingEnd="5dp"
android:contentDescription="Back Icon"
android:src="@drawable/back_icon_pixelated"
app:tint="@color/primary_color" />

Expand All @@ -33,12 +34,12 @@
android:textAlignment="center"
android:textColor="@color/primary_color"
android:textSize="20sp"
android:paddingRight="8dp"/>
android:paddingRight="12dp"/>
</androidx.appcompat.widget.Toolbar>

<LinearLayout
android:layout_width="match_parent"
android:layout_height="106dp"
android:layout_height="198dp"
android:layout_margin="20dp"
android:background="@drawable/pixel_frame_border"
android:orientation="vertical">
Expand All @@ -54,10 +55,24 @@
android:text="Select Time Zone: "
android:textColor="@color/accent_color" />

<EditText
android:id="@+id/searchbox"
android:layout_width="match_parent"
android:layout_height="50dp"
android:textColor="@color/primary_color"
android:layout_marginTop="10dp"
android:textColorHint="@color/secondary_color"
android:hint="eg. Asia"
android:textSize="12sp"
android:fontFamily="@font/dogicapixelbold"
android:background="@drawable/pixel_frame_border"
android:drawableStart="@drawable/search_pixelated_icon"
android:drawablePadding="10dp" />

<TextView
android:id="@+id/selected_time_zone_txt"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_height="70dp"
android:layout_margin="5dp"
android:background="@drawable/pixel_frame_border"
android:drawableEnd="@drawable/drop_down_pixelated"
Expand Down Expand Up @@ -86,5 +101,4 @@
</LinearLayout>



</LinearLayout>
2 changes: 1 addition & 1 deletion app/src/main/res/values/colors.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@
<color name="status_bar_color">#000000</color>

<color name="accent_color">#CD0404</color>
<color name="secondary_color">#952323</color>
<color name="secondary_color">#780000</color>

</resources>
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[versions]
agp = "8.2.0-alpha10"
agp = "8.3.0-alpha04"
junit = "4.13.2"
androidx-test-ext-junit = "1.1.5"
espresso-core = "3.5.1"
Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Wed Aug 16 20:10:10 PKT 2023
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.1-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.3-rc-2-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists

0 comments on commit 3776222

Please sign in to comment.