-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMainActivity.java
More file actions
133 lines (109 loc) · 4.37 KB
/
Copy pathMainActivity.java
File metadata and controls
133 lines (109 loc) · 4.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
package com.example.trip_packer;
import android.annotation.SuppressLint;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import com.example.trip_packer.Data.AppData;
import com.example.trip_packer.Database.RoomDB;
import com.example.trip_packer.R;
import com.example.trip_packer.adapter.MyAdapter;
import com.example.trip_packer.constants.myconstants;
import com.google.android.material.floatingactionbutton.FloatingActionButton;
import java.util.ArrayList;
import java.util.List;
public class MainActivity extends AppCompatActivity {
RecyclerView recyclerView;
List<String> titles;
List<Integer> images;
RecyclerView.Adapter adapter;
RoomDB database;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
getSupportActionBar().hide();
FloatingActionButton fabWeather = findViewById(R.id.fabWeather);
fabWeather.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
openWeatherService();
}
});
addAddTitles();
addAllImages();
persistAppData();
database = RoomDB.getInstance(this);
recyclerView = findViewById(R.id.recyclerview);
MyAdapter myAdapter = new MyAdapter(this, titles, images, MainActivity.this);
recyclerView.setAdapter(myAdapter);
GridLayoutManager gridLayoutManager = new GridLayoutManager(this, 2, GridLayoutManager.VERTICAL, false);
recyclerView.setLayoutManager(gridLayoutManager);
recyclerView.setAdapter(myAdapter);
}
private void addAddTitles() {
titles = new ArrayList<>();
titles.add(myconstants.BASIC_NEEDS_CAMEL_CASE);
titles.add(myconstants.CLOTHING_CAMEL_CASE);
titles.add(myconstants.PERSONAL_CARE_CAMEL_CASE);
titles.add(myconstants.BABY_NEEDS_CAMEL_CASE);
titles.add(myconstants.HEALTH_CAMEL_CASE);
titles.add(myconstants.TECHNOLOGY_CAMEL_CASE);
titles.add(myconstants.FOOD_CAMEL_CASE);
titles.add(myconstants.BEACH_SUPPLIES_CAMEL_CASE);
titles.add(myconstants.CAR_SUPPLIES_CAMEL_CASE);
titles.add(myconstants.NEEDS_CAMEL_CASE);
titles.add(myconstants.MY_LIST_CAMEL_CASE);
titles.add(myconstants.MY_SELECTIONS_CAMEL_CASE);
}
@Override
public void onBackPressed() {
super.onBackPressed();
}
private void persistAppData() {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
SharedPreferences.Editor editor = prefs.edit();
database = RoomDB.getInstance(this);
AppData appData = new AppData(database);
int last = prefs.getInt(AppData.LAST_VERSION, 0);
if (!prefs.getBoolean(myconstants.FIRST_TIME_CAMEL_CASE, false)) {
appData.persistAllData();
editor.putBoolean(myconstants.FIRST_TIME_CAMEL_CASE, true);
editor.apply();
} else if (last < AppData.NEW_VERSION) {
database.mainDao().deleteAllSystemItems(myconstants.SYSTEM_SMALL);
appData.persistAllData();
editor.putInt(AppData.LAST_VERSION, AppData.NEW_VERSION);
editor.apply();
}
}
private void addAllImages() {
images = new ArrayList<>();
images.add(R.drawable.pi1);
images.add(R.drawable.pi2);
images.add(R.drawable.pi3);
images.add(R.drawable.pi4);
images.add(R.drawable.pi5);
images.add(R.drawable.pi6);
images.add(R.drawable.pi7);
images.add(R.drawable.pi8);
images.add(R.drawable.pi9);
images.add(R.drawable.pi10);
images.add(R.drawable.pi11);
images.add(R.drawable.pi12);
}
public void openWeatherService() {
Intent intent = new Intent(this, WeatherService.class);
startActivity(intent);
}
}