diff --git a/StormMonitor.apk b/StormMonitor.apk index 922e77c..9b08657 100644 Binary files a/StormMonitor.apk and b/StormMonitor.apk differ diff --git a/StormMonitor/src/main/AndroidManifest.xml b/StormMonitor/src/main/AndroidManifest.xml index a023155..27f0727 100644 --- a/StormMonitor/src/main/AndroidManifest.xml +++ b/StormMonitor/src/main/AndroidManifest.xml @@ -2,7 +2,7 @@ + android:versionName="1.4.10"> - + + + + + android:theme="@style/AppTheme"> + android:label="@string/app_name"> @@ -31,37 +34,41 @@ + android:screenOrientation="portrait"> - + + + @@ -72,7 +79,7 @@ ... params) { if (params[0] != null) { // We list of the cities so download process can be started - result = Downloader.getStormData(params[0]); + result = Utils.getStormData(params[0]); Answers.getInstance().logContentView(new ContentViewEvent() .putContentName("Widget") .putContentType("Action") @@ -87,9 +97,7 @@ protected void onPreExecute(){ } public void RefreshData() { - StormOpenHelper db = new StormOpenHelper(ctx); - List cities = db.getAllCities(); - db.close(); + List cities = Utils.getAllData(context); JSONStormTask task = new JSONStormTask(); task.execute(cities); diff --git a/StormMonitor/src/main/java/pl/revanmj/stormmonitor/DetailsActivity.java b/StormMonitor/src/main/java/pl/revanmj/stormmonitor/DetailsActivity.java index d371e14..d01824e 100644 --- a/StormMonitor/src/main/java/pl/revanmj/stormmonitor/DetailsActivity.java +++ b/StormMonitor/src/main/java/pl/revanmj/stormmonitor/DetailsActivity.java @@ -19,6 +19,9 @@ import im.delight.android.webview.AdvancedWebView; +/** + * Created by revanmj on 25.01.2015. + */ public class DetailsActivity extends AppCompatActivity { diff --git a/StormMonitor/src/main/java/pl/revanmj/stormmonitor/MainActivity.java b/StormMonitor/src/main/java/pl/revanmj/stormmonitor/MainActivity.java index b0d387b..b48690a 100644 --- a/StormMonitor/src/main/java/pl/revanmj/stormmonitor/MainActivity.java +++ b/StormMonitor/src/main/java/pl/revanmj/stormmonitor/MainActivity.java @@ -1,26 +1,33 @@ package pl.revanmj.stormmonitor; +import android.content.ContentValues; import android.content.Intent; +import android.database.Cursor; import android.os.AsyncTask; import android.os.Bundle; +import android.support.design.widget.FloatingActionButton; import android.support.design.widget.Snackbar; +import android.support.v4.app.LoaderManager; +import android.support.v4.content.CursorLoader; +import android.support.v4.content.Loader; import android.support.v4.widget.SwipeRefreshLayout; import android.support.v7.app.AppCompatActivity; -import android.view.ContextMenu; +import android.support.v7.widget.LinearLayoutManager; +import android.support.v7.widget.RecyclerView; +import android.support.v7.widget.helper.ItemTouchHelper; +import android.util.Log; import android.view.Menu; -import android.view.MenuInflater; import android.view.MenuItem; import android.view.View; -import android.widget.AdapterView; -import android.widget.ListView; import com.crashlytics.android.Crashlytics; -import pl.revanmj.stormmonitor.adapters.MainViewAdapter; -import pl.revanmj.stormmonitor.logic.Downloader; +import pl.revanmj.stormmonitor.adapters.MainRecyclerViewAdapter; +import pl.revanmj.stormmonitor.data.StormDataProvider; +import pl.revanmj.stormmonitor.logic.Utils; +import pl.revanmj.stormmonitor.logic.SwipeToDelTouchCallback; import pl.revanmj.stormmonitor.model.DownloadResult; import pl.revanmj.stormmonitor.model.StormData; -import pl.revanmj.stormmonitor.sql.StormOpenHelper; import com.crashlytics.android.answers.Answers; import com.crashlytics.android.answers.ContentViewEvent; @@ -30,7 +37,11 @@ import java.util.List; -public class MainActivity extends AppCompatActivity { +/** + * Created by revanmj on 14.07.2013. + */ + +public class MainActivity extends AppCompatActivity implements LoaderManager.LoaderCallbacks { // Data for updater from WVersionManager library private final String updateApkUrl = "https://github.com/revanmj/StormMonitor/raw/master/StormMonitor.apk"; private final String updateChangelogUrl = "https://github.com/revanmj/StormMonitor/raw/master/updates.json"; @@ -38,8 +49,8 @@ public class MainActivity extends AppCompatActivity { // URL for opening a map in WebView private final String serviceUrl = "http://antistorm.eu/"; - private List cityStorm; - private MainViewAdapter sdAdapter; + private MainRecyclerViewAdapter rcAdapter; + private RecyclerView recyclerView; private SwipeRefreshLayout mySwipeRefreshLayout; @Override @@ -48,11 +59,7 @@ protected void onCreate(Bundle savedInstanceState) { Fabric.with(this, new Crashlytics()); setContentView(R.layout.activity_main); - // Getting all cities from the database - StormOpenHelper db = new StormOpenHelper(this); - cityStorm = db.getAllCities(); - db.close(); - + recyclerView = (RecyclerView) findViewById(R.id.recyclerView); mySwipeRefreshLayout = (SwipeRefreshLayout)findViewById(R.id.swiperefresh); mySwipeRefreshLayout.setOnRefreshListener( @@ -67,11 +74,32 @@ public void onRefresh() { ); mySwipeRefreshLayout.setColorSchemeResources(R.color.md_blue_500); - // Setting up the ListView - sdAdapter = new MainViewAdapter(cityStorm, this); - ListView lista = (ListView) findViewById(R.id.listView); - lista.setAdapter(sdAdapter); - registerForContextMenu(lista); + // Setting up FAB + FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab_map); + fab.show(); + fab.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + Intent browserIntent = new Intent(MainActivity.this, DetailsActivity.class); + browserIntent.putExtra("url", serviceUrl + "/m/"); + browserIntent.putExtra("title", "map"); + startActivity(browserIntent); + } + }); + + // Setting up RecyclerView + rcAdapter = new MainRecyclerViewAdapter(this); + recyclerView.setAdapter(rcAdapter); + recyclerView.setHasFixedSize(true); + LinearLayoutManager llm = new LinearLayoutManager(this); + llm.setOrientation(LinearLayoutManager.VERTICAL); + recyclerView.setLayoutManager(llm); + + SwipeToDelTouchCallback stdcallback = new SwipeToDelTouchCallback(this); + ItemTouchHelper mItemTouchHelper = new ItemTouchHelper(stdcallback); + mItemTouchHelper.attachToRecyclerView(recyclerView); + + getSupportLoaderManager().initLoader(1, null, this); // Setting up updater form WVersionManager library WVersionManager versionManager = new WVersionManager(this); @@ -99,13 +127,18 @@ public boolean onCreateOptionsMenu(Menu menu) { } @Override - public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) { - super.onCreateContextMenu(menu, v, menuInfo); + public Loader onCreateLoader(int id, Bundle args) { + return new CursorLoader(this, StormDataProvider.CONTENT_URI, null, null, null, null); + } - if (v.getId() == R.id.listView) { - MenuInflater inflater = getMenuInflater(); - inflater.inflate(R.menu.context, menu); - } + @Override + public void onLoadFinished(Loader loader, Cursor data) { + rcAdapter.swapCursor(data); + } + + @Override + public void onLoaderReset(Loader loader) { + rcAdapter.swapCursor(null); } /** @@ -116,18 +149,18 @@ public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMen private void setData(DownloadResult result) { if (result.getResultCode() == 1) { - StormOpenHelper db = new StormOpenHelper(this); for (StormData city : result.getCitiesData()) { - db.updateCity(city); + ContentValues cv = new ContentValues(); + cv.put(StormDataProvider.KEY_STORMCHANCE, city.getStormChance()); + cv.put(StormDataProvider.KEY_STORMTIME, city.getStormTime()); + cv.put(StormDataProvider.KEY_RAINCHANCE, city.getRainChance()); + cv.put(StormDataProvider.KEY_RAINTIME, city.getRainTime()); + String selection = StormDataProvider.KEY_ID + " = ?"; + String[] selArgs = {Integer.toString(city.getCityId())}; + getContentResolver().update(StormDataProvider.CONTENT_URI, cv, selection, selArgs); } - cityStorm = db.getAllCities(); - db.close(); - - sdAdapter.clear(); - sdAdapter.addAll(cityStorm); - sdAdapter.notifyDataSetChanged(); } else { String error = getResources().getString(R.string.error_unknown) + result.getResultCode(); @@ -156,7 +189,7 @@ protected DownloadResult doInBackground(List... params) { if (params[0] != null) { // We list of the cities so download process can be started - result = Downloader.getStormData(params[0]); + result = Utils.getStormData(params[0]); } return result; @@ -174,33 +207,6 @@ protected void onPreExecute(){ } } - /** - * Method supporting context menu of the ListView - */ - @Override - public boolean onContextItemSelected(MenuItem item) { - AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) item.getMenuInfo(); - switch(item.getItemId()) { - case R.id.context_delete: - StormOpenHelper db = new StormOpenHelper(this); - db.deleteCity(cityStorm.get(info.position)); - cityStorm = db.getAllCities(); - db.close(); - - sdAdapter.clear(); - sdAdapter.addAll(cityStorm); - sdAdapter.notifyDataSetChanged(); - - Answers.getInstance().logContentView(new ContentViewEvent() - .putContentName("MainView") - .putContentType("Action") - .putContentId("deletedCity")); - - return true; - } - return true; - } - /** * Method supporting ActionBar's menu */ @@ -216,12 +222,6 @@ public boolean onOptionsItemSelected(MenuItem item) { Intent about = new Intent(MainActivity.this, AboutActivity.class); MainActivity.this.startActivity(about); return true; - case R.id.action_map: - Intent browserIntent = new Intent(MainActivity.this, DetailsActivity.class); - browserIntent.putExtra("url", serviceUrl + "/m/"); - browserIntent.putExtra("title", "map"); - startActivity(browserIntent); - return true; case R.id.action_refresh: RefreshData(false); return true; @@ -237,11 +237,10 @@ public void RefreshData(Boolean byGesture) { if (!byGesture) mySwipeRefreshLayout.setRefreshing(true); - StormOpenHelper db = new StormOpenHelper(this); - cityStorm = db.getAllCities(); - db.close(); + List cities = Utils.getAllData(this); + Log.d("StormMonitor", "Initating data downloading, city ids: " + cities); JSONStormTask task = new JSONStormTask(); - task.execute(cityStorm); + task.execute(cities); } } diff --git a/StormMonitor/src/main/java/pl/revanmj/stormmonitor/MapActivity.java b/StormMonitor/src/main/java/pl/revanmj/stormmonitor/MapActivity.java index abdcca9..e861af7 100644 --- a/StormMonitor/src/main/java/pl/revanmj/stormmonitor/MapActivity.java +++ b/StormMonitor/src/main/java/pl/revanmj/stormmonitor/MapActivity.java @@ -33,6 +33,10 @@ import it.sephiroth.android.library.imagezoom.ImageViewTouch; +/** + * Created by revanmj on 7.12.2013. + */ + public class MapActivity extends AppCompatActivity { private final String serviceUrl = "http://antistorm.eu/"; diff --git a/StormMonitor/src/main/java/pl/revanmj/stormmonitor/SearchActivity.java b/StormMonitor/src/main/java/pl/revanmj/stormmonitor/SearchActivity.java index 2056afd..ff239af 100644 --- a/StormMonitor/src/main/java/pl/revanmj/stormmonitor/SearchActivity.java +++ b/StormMonitor/src/main/java/pl/revanmj/stormmonitor/SearchActivity.java @@ -2,6 +2,7 @@ import android.app.Activity; import android.app.ProgressDialog; +import android.content.ContentValues; import android.content.Context; import android.content.pm.PackageManager; import android.database.Cursor; @@ -32,23 +33,27 @@ import com.crashlytics.android.answers.ContentViewEvent; import pl.revanmj.stormmonitor.adapters.SearchAdapter; +import pl.revanmj.stormmonitor.data.StormDataProvider; +import pl.revanmj.stormmonitor.logic.Utils; import pl.revanmj.stormmonitor.model.StormData; -import pl.revanmj.stormmonitor.sql.CitiesAssetHelper; -import pl.revanmj.stormmonitor.sql.StormOpenHelper; +import pl.revanmj.stormmonitor.data.CitiesAssetHelper; import java.io.IOException; import java.util.ArrayList; import java.util.List; import java.util.Locale; -import java.util.jar.Manifest; + +/** + * Created by revanmj on 29.12.2013. + */ public class SearchActivity extends AppCompatActivity implements TextWatcher { - private ListView wyniki; - private EditText pole; - private SearchAdapter sAdapter; + private ListView resultsListView; + private EditText searchField; + private SearchAdapter searchAdapter; private List cities; - private List res; + private List results; @Override protected void onCreate(Bundle savedInstanceState) { @@ -64,26 +69,20 @@ protected void onCreate(Bundle savedInstanceState) { .putContentId("addView")); // Get list of all cities - StormOpenHelper db = new StormOpenHelper(SearchActivity.this); - cities = db.getAllCities(); - db.close(); + cities = Utils.getAllData(this); // Prepare ListView - res = new ArrayList<>(); - sAdapter = new SearchAdapter(res, this); - wyniki = (ListView)findViewById(R.id.list_search); - wyniki.setAdapter(sAdapter); - pole = (EditText)findViewById(R.id.editText); + results = new ArrayList<>(); + searchAdapter = new SearchAdapter(results, this); + resultsListView = (ListView)findViewById(R.id.list_search); + resultsListView.setAdapter(searchAdapter); + searchField = (EditText)findViewById(R.id.editText); // Add listener for Search key presses on virtual keyboard - pole.setOnKeyListener(new View.OnKeyListener() - { - public boolean onKey(View v, int keyCode, KeyEvent event) - { - if (event.getAction() == KeyEvent.ACTION_DOWN) - { - switch (keyCode) - { + searchField.setOnKeyListener(new View.OnKeyListener() { + public boolean onKey(View v, int keyCode, KeyEvent event) { + if (event.getAction() == KeyEvent.ACTION_DOWN) { + switch (keyCode) { case KeyEvent.KEYCODE_DPAD_CENTER: case KeyEvent.KEYCODE_ENTER: doSearch(); @@ -97,14 +96,14 @@ public boolean onKey(View v, int keyCode, KeyEvent event) return false; } }); - pole.addTextChangedListener(this); + searchField.addTextChangedListener(this); } /** * Main method for searching the database */ public void doSearch() { - String query = pole.getText().toString(); + String query = searchField.getText().toString(); // Remove polish letters if (query.toLowerCase().startsWith("ą") || query.toLowerCase().startsWith("ć") || query.toLowerCase().startsWith("ę") || query.toLowerCase().startsWith("ł") || query.toLowerCase().startsWith("ń") || query.toLowerCase().startsWith("ó") || query.toLowerCase().startsWith("ś") || query.toLowerCase().startsWith("ż") || query.toLowerCase().startsWith("ź")) { @@ -120,8 +119,8 @@ public void doSearch() { if (cursor.moveToFirst()) { do { StormData city = new StormData(); - city.setMiasto_id(Integer.parseInt(cursor.getString(0))); - city.setMiasto(cursor.getString(1)); + city.setCityId(Integer.parseInt(cursor.getString(0))); + city.setCityName(cursor.getString(1)); results.add(city); } while (cursor.moveToNext()); @@ -132,20 +131,21 @@ public void doSearch() { Toast.makeText(SearchActivity.this, R.string.message_no_results, Toast.LENGTH_SHORT).show(); } else { // Clear the ListView and add results to it - sAdapter.clear(); - sAdapter.addAll(results); - sAdapter.notifyDataSetChanged(); + searchAdapter.clear(); + searchAdapter.addAll(results); + searchAdapter.notifyDataSetChanged(); - wyniki.setOnItemClickListener(new AdapterView.OnItemClickListener() { + resultsListView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView parent, View view, int position, long id) { // Add clicked city to the database - StormData tmp = cities_db.getCity(results.get(position).getMiasto()); + StormData tmp = cities_db.getCity(results.get(position).getCityName()); if (tmp != null) { - if (!cityExists(tmp.getMiasto_id())) { - StormOpenHelper db = new StormOpenHelper(SearchActivity.this); - db.addCity(tmp); - db.close(); + if (!cityExists(tmp.getCityId())) { + ContentValues cv = new ContentValues(); + cv.put(StormDataProvider.KEY_ID, tmp.getCityId()); + cv.put(StormDataProvider.KEY_CITYNAME, tmp.getCityName()); + getContentResolver().insert(StormDataProvider.CONTENT_URI, cv); Answers.getInstance().logContentView(new ContentViewEvent() .putContentName("AddView") @@ -215,10 +215,11 @@ private void addLocationCity(String data) { CitiesAssetHelper cities_db = new CitiesAssetHelper(this); StormData tmp = cities_db.getCity(data); if (tmp != null) { - if (!cityExists(tmp.getMiasto_id())) { - StormOpenHelper db = new StormOpenHelper(this); - db.addCity(tmp); - db.close(); + if (!cityExists(tmp.getCityId())) { + ContentValues cv = new ContentValues(); + cv.put(StormDataProvider.KEY_ID, tmp.getCityId()); + cv.put(StormDataProvider.KEY_CITYNAME, tmp.getCityName()); + getContentResolver().insert(StormDataProvider.CONTENT_URI, cv); Answers.getInstance().logContentView(new ContentViewEvent() .putContentName("AddView") @@ -240,7 +241,7 @@ private void addLocationCity(String data) { private boolean cityExists(int cityId) { for (int i = 0; i < cities.size(); i++) - if (cities.get(i).getMiasto_id() == cityId) + if (cities.get(i).getCityId() == cityId) return true; return false; } @@ -294,22 +295,22 @@ protected String doInBackground(String... params) { String result = ""; LocationManager locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); - Criteria criteria = new Criteria(); - String provider = locationManager.getBestProvider(criteria, false); - Location location = locationManager.getLastKnownLocation(provider); - latitude = location.getLatitude(); - longitude = location.getLongitude(); - - Geocoder geocoder = new Geocoder(act, Locale.getDefault()); try { - List
addresses = geocoder.getFromLocation(latitude, - longitude, 1); - Log.e("Addresses", "-->" + addresses); - Address tmp = addresses.get(0); - result = tmp.getLocality(); - } catch (IOException e) { - e.printStackTrace(); - } + Criteria criteria = new Criteria(); + String provider = locationManager.getBestProvider(criteria, false); + Location location = locationManager.getLastKnownLocation(provider); + + latitude = location.getLatitude(); + longitude = location.getLongitude(); + + Geocoder geocoder = new Geocoder(act, Locale.getDefault()); + try { + List
addresses = geocoder.getFromLocation(latitude, longitude, 1); + Log.e("Addresses", "-->" + addresses); + Address tmp = addresses.get(0); + result = tmp.getLocality(); + } catch (IOException e) {e.printStackTrace();} + } catch (SecurityException e) {} return result; } diff --git a/StormMonitor/src/main/java/pl/revanmj/stormmonitor/WidgetListProvider.java b/StormMonitor/src/main/java/pl/revanmj/stormmonitor/WidgetListProvider.java index ee74189..1c76a01 100644 --- a/StormMonitor/src/main/java/pl/revanmj/stormmonitor/WidgetListProvider.java +++ b/StormMonitor/src/main/java/pl/revanmj/stormmonitor/WidgetListProvider.java @@ -6,8 +6,8 @@ import android.widget.RemoteViews; import android.widget.RemoteViewsService; +import pl.revanmj.stormmonitor.logic.Utils; import pl.revanmj.stormmonitor.model.StormData; -import pl.revanmj.stormmonitor.sql.StormOpenHelper; import java.text.DecimalFormat; import java.util.List; @@ -15,6 +15,7 @@ /** * Created by revanmj on 26.12.2013. */ + public class WidgetListProvider implements RemoteViewsService.RemoteViewsFactory { private List cities; private Context context = null; @@ -28,9 +29,7 @@ public WidgetListProvider(Context context, Intent intent) { } private void populateListItem() { - StormOpenHelper db = new StormOpenHelper(context); - cities = db.getAllCities(); - db.close(); + cities = Utils.getAllData(context); } @Override @@ -49,13 +48,13 @@ public RemoteViews getViewAt(int position) { context.getPackageName(), R.layout.cities_widget_row); StormData listItem = cities.get(position); - int t = listItem.getT_burzy(); - int t_r = listItem.getT_opadow(); - float chancePercentage = (listItem.getP_burzy() * 100.0f) / 255; - float rainChancePercentage = (listItem.getP_opadow() * 100.0f) / 255; + int t = listItem.getStormTime(); + int t_r = listItem.getRainTime(); + float chancePercentage = (listItem.getStormChance() * 100.0f) / 255; + float rainChancePercentage = (listItem.getRainChance() * 100.0f) / 255; DecimalFormat form = new DecimalFormat("##.##"); - remoteView.setTextViewText(R.id.widget_cityText, listItem.getMiasto()); + remoteView.setTextViewText(R.id.widget_cityText, listItem.getCityName()); remoteView.setTextViewText(R.id.widget_chanceText, form.format(chancePercentage) + " %"); remoteView.setTextViewText(R.id.widget_rainChance, form.format(rainChancePercentage) + " %"); diff --git a/StormMonitor/src/main/java/pl/revanmj/stormmonitor/WidgetService.java b/StormMonitor/src/main/java/pl/revanmj/stormmonitor/WidgetService.java index 81c6aa2..c6e160c 100644 --- a/StormMonitor/src/main/java/pl/revanmj/stormmonitor/WidgetService.java +++ b/StormMonitor/src/main/java/pl/revanmj/stormmonitor/WidgetService.java @@ -3,6 +3,7 @@ /** * Created by revanmj on 26.12.2013. */ + import android.appwidget.AppWidgetManager; import android.content.Intent; import android.widget.RemoteViewsService; diff --git a/StormMonitor/src/main/java/pl/revanmj/stormmonitor/adapters/MainRecyclerViewAdapter.java b/StormMonitor/src/main/java/pl/revanmj/stormmonitor/adapters/MainRecyclerViewAdapter.java new file mode 100644 index 0000000..ef193be --- /dev/null +++ b/StormMonitor/src/main/java/pl/revanmj/stormmonitor/adapters/MainRecyclerViewAdapter.java @@ -0,0 +1,119 @@ +package pl.revanmj.stormmonitor.adapters; + +import android.content.Context; +import android.database.Cursor; +import android.support.v7.widget.RecyclerView; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.ImageView; +import android.widget.TextView; + +import java.text.DecimalFormat; + +import pl.revanmj.stormmonitor.R; +import pl.revanmj.stormmonitor.data.StormDataProvider; + +/** + * Created by revanmj on 05.02.2016. + */ + +public class MainRecyclerViewAdapter extends RecyclerView.Adapter { + private Context context; + private Cursor cursor; + + public MainRecyclerViewAdapter(Context c) { + context = c; + } + + public void swapCursor(Cursor c) { + cursor = c; + notifyDataSetChanged(); + } + + @Override + public StormDataViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { + View itemView = LayoutInflater. + from(parent.getContext()). + inflate(R.layout.row_listview, parent, false); + + return new StormDataViewHolder(itemView); + } + + @Override + public void onBindViewHolder(StormDataViewHolder holder, int position) { + Cursor item = getItem(position); + int stormTime = item.getInt(StormDataProvider.STORMTIME); + int rainTime = item.getInt(StormDataProvider.RAINTIME); + float stormChance = (item.getInt(StormDataProvider.STORMCHANCE) * 100.0f) / 255; + float rainChance = (item.getInt(StormDataProvider.RAINCHANCE) * 100.0f) / 255; + + holder._id = item.getInt(StormDataProvider.CITYID); + holder.city.setText(item.getString(StormDataProvider.CITYNAME)); + DecimalFormat form = new DecimalFormat("##.##"); + holder.stormChanceLabel.setText(form.format(stormChance)); + holder.rainChanceLabel.setText(form.format(rainChance)); + + if (stormTime < 240) { + holder.stormTimeLabel.setText("~ " + stormTime + " min"); + } else { + holder.stormTimeLabel.setText("-"); + } + if (rainTime < 240) { + holder.rainTimeLabel.setText("~ " + rainTime + " min"); + } else { + holder.rainTimeLabel.setText("-"); + } + if (stormTime <= 120 && stormChance > 30 && stormChance < 50 || rainTime <= 120 && rainChance > 30 && rainChance < 50) + holder.rect.setImageResource(R.drawable.rectangle_yellow); + else if (stormTime <= 20 && stormChance >= 50 || rainTime <= 20 && rainChance >= 50) + holder.rect.setImageResource(R.drawable.rectangle_red); + else if (stormTime <= 60 && stormChance > 30 || rainTime <= 60 && rainChance > 30) + holder.rect.setImageResource(R.drawable.rectangle_orange); + else + holder.rect.setImageResource(R.drawable.rectangle_green); + + } + + @Override + public int getItemCount() { + if (cursor != null) + return cursor.getCount(); + else + return 0; + } + + public Cursor getItem(int pos) { + if (this.cursor != null && !this.cursor.isClosed()) + { + this.cursor.moveToPosition(pos); + } + + return this.cursor; + } + + public static class StormDataViewHolder extends RecyclerView.ViewHolder { + public int _id; + protected TextView city; + protected TextView stormChanceLabel; + protected TextView stormTimeLabel; + protected TextView timeN; + protected TextView rainTimeLabel; + protected TextView rainTimeN; + protected TextView rainChanceLabel; + protected ImageView rect; + + public StormDataViewHolder(View itemView) { + super(itemView); + + city = (TextView) itemView.findViewById(R.id.cityText); + stormChanceLabel = (TextView) itemView.findViewById(R.id.chanceText); + stormTimeLabel = (TextView) itemView.findViewById(R.id.timeText); + timeN = (TextView) itemView.findViewById(R.id.textView3); + rect = (ImageView) itemView.findViewById(R.id.colorRectangle); + rainChanceLabel = (TextView) itemView.findViewById(R.id.rainChance); + rainTimeLabel = (TextView) itemView.findViewById(R.id.rainTime); + rainTimeN = (TextView) itemView.findViewById(R.id.textView4); + } + } +} diff --git a/StormMonitor/src/main/java/pl/revanmj/stormmonitor/adapters/MainViewAdapter.java b/StormMonitor/src/main/java/pl/revanmj/stormmonitor/adapters/MainViewAdapter.java index 04150f8..9ea1627 100644 --- a/StormMonitor/src/main/java/pl/revanmj/stormmonitor/adapters/MainViewAdapter.java +++ b/StormMonitor/src/main/java/pl/revanmj/stormmonitor/adapters/MainViewAdapter.java @@ -15,8 +15,9 @@ import java.util.List; /** - * Created by revan_000 on 14.07.13. + * Created by revanmj on 14.07.2013. */ + public class MainViewAdapter extends ArrayAdapter { private List cityList; @@ -30,8 +31,8 @@ public MainViewAdapter(List cityList, Context ctx) { public View getView(int position, View convertView, ViewGroup parent) { StormData d = cityList.get(position); - int t = d.getT_burzy(); - int t_r = d.getT_opadow(); + int t = d.getStormTime(); + int t_r = d.getRainTime(); ViewHolder holder; if (convertView == null) { @@ -60,9 +61,9 @@ public View getView(int position, View convertView, ViewGroup parent) { TextView rainChance = holder.rainChance; ImageView rect = holder.rect; - city.setText(d.getMiasto()); - float chancePercentage = (d.getP_burzy() * 100.0f) / 255; - float rainChancePercentage = (d.getP_opadow() * 100.0f) / 255; + city.setText(d.getCityName()); + float chancePercentage = (d.getStormChance() * 100.0f) / 255; + float rainChancePercentage = (d.getRainChance() * 100.0f) / 255; DecimalFormat form = new DecimalFormat("##.##"); chance.setText(form.format(chancePercentage) + " %"); rainChance.setText(form.format(rainChancePercentage) + " %"); diff --git a/StormMonitor/src/main/java/pl/revanmj/stormmonitor/adapters/SearchAdapter.java b/StormMonitor/src/main/java/pl/revanmj/stormmonitor/adapters/SearchAdapter.java index 6d37165..119be7d 100644 --- a/StormMonitor/src/main/java/pl/revanmj/stormmonitor/adapters/SearchAdapter.java +++ b/StormMonitor/src/main/java/pl/revanmj/stormmonitor/adapters/SearchAdapter.java @@ -15,6 +15,7 @@ /** * Created by revanmj on 29.12.2013. */ + public class SearchAdapter extends ArrayAdapter { private List cityList; @@ -44,7 +45,7 @@ public View getView(int position, View convertView, ViewGroup parent) { TextView city = holder.city; - city.setText(d.getMiasto()); + city.setText(d.getCityName()); return convertView; } diff --git a/StormMonitor/src/main/java/pl/revanmj/stormmonitor/sql/CitiesAssetHelper.java b/StormMonitor/src/main/java/pl/revanmj/stormmonitor/data/CitiesAssetHelper.java similarity index 91% rename from StormMonitor/src/main/java/pl/revanmj/stormmonitor/sql/CitiesAssetHelper.java rename to StormMonitor/src/main/java/pl/revanmj/stormmonitor/data/CitiesAssetHelper.java index 5e370ec..4e04763 100644 --- a/StormMonitor/src/main/java/pl/revanmj/stormmonitor/sql/CitiesAssetHelper.java +++ b/StormMonitor/src/main/java/pl/revanmj/stormmonitor/data/CitiesAssetHelper.java @@ -1,4 +1,4 @@ -package pl.revanmj.stormmonitor.sql; +package pl.revanmj.stormmonitor.data; import android.content.Context; import android.database.Cursor; @@ -11,6 +11,7 @@ /** * Created by revanmj on 29.12.2013. */ + public class CitiesAssetHelper extends SQLiteAssetHelper { private static final String DATABASE_NAME = "cities"; private static final int DATABASE_VERSION = 2; @@ -37,8 +38,8 @@ public StormData getCity(String city_name) { StormData city = null; if (c.moveToFirst()) { city = new StormData(); - city.setMiasto_id(Integer.parseInt(c.getString(0))); - city.setMiasto(c.getString(1)); + city.setCityId(Integer.parseInt(c.getString(0))); + city.setCityName(c.getString(1)); } return city; diff --git a/StormMonitor/src/main/java/pl/revanmj/stormmonitor/data/StormDataProvider.java b/StormMonitor/src/main/java/pl/revanmj/stormmonitor/data/StormDataProvider.java new file mode 100644 index 0000000..c208b70 --- /dev/null +++ b/StormMonitor/src/main/java/pl/revanmj/stormmonitor/data/StormDataProvider.java @@ -0,0 +1,235 @@ +package pl.revanmj.stormmonitor.data; + +import android.content.ContentProvider; +import android.content.ContentUris; +import android.content.ContentValues; +import android.content.Context; +import android.content.UriMatcher; +import android.database.Cursor; +import android.database.SQLException; +import android.database.sqlite.SQLiteDatabase; +import android.database.sqlite.SQLiteOpenHelper; +import android.database.sqlite.SQLiteQueryBuilder; +import android.net.Uri; +import android.text.TextUtils; + +import java.util.HashMap; +import java.util.LinkedList; +import java.util.List; + +import pl.revanmj.stormmonitor.model.StormData; + +/** + * Created by revanmj on 05.02.2016. + */ + +public class StormDataProvider extends ContentProvider { + public static int CITYID = 0; + public static int CITYNAME = 1; + public static int STORMCHANCE = 2; + public static int STORMTIME = 3; + public static int RAINCHANCE = 4; + public static int RAINTIME = 5; + + public static final String PROVIDER_NAME = "pl.revanmj.provider.StormData"; + public static final String URL = "content://" + PROVIDER_NAME + "/cities"; + public static final Uri CONTENT_URI = Uri.parse(URL); + private static HashMap CITIES_PROJECTION_MAP; + + static final int URI_CITIES = 1; + static final int URI_CITYID = 2; + + static final UriMatcher uriMatcher; + static{ + uriMatcher = new UriMatcher(UriMatcher.NO_MATCH); + uriMatcher.addURI(PROVIDER_NAME, "cities", URI_CITIES); + uriMatcher.addURI(PROVIDER_NAME, "cities/#", URI_CITYID); + } + + @Override + public boolean onCreate() { + Context context = getContext(); + StormDataSqlHelper dbHelper = new StormDataSqlHelper(context); + + db = dbHelper.getWritableDatabase(); + return (db != null); + } + + @Override + public Cursor query(Uri uri, String[] projection, String selection,String[] selectionArgs, String sortOrder) { + SQLiteQueryBuilder qb = new SQLiteQueryBuilder(); + qb.setTables(TABLE_STORMS); + + switch (uriMatcher.match(uri)) { + case URI_CITIES: + qb.setProjectionMap(CITIES_PROJECTION_MAP); + break; + + case URI_CITYID: + qb.appendWhere( CITYID + "=" + uri.getPathSegments().get(1)); + break; + + default: + throw new IllegalArgumentException("Unknown URI " + uri); + } + + if (sortOrder == null || sortOrder == ""){ + // By default sort on cities names + sortOrder = KEY_CITYNAME; + } + Cursor c = qb.query(db, projection, selection, selectionArgs,null, null, sortOrder); + + // register to watch a content URI for changes + c.setNotificationUri(getContext().getContentResolver(), uri); + return c; + } + + @Override + public String getType(Uri uri) { + switch (uriMatcher.match(uri)){ + // Get all cities + case URI_CITIES: + return "vnd.android.cursor.dir/vnd.revanmj.cities"; + + // Get specific city + case URI_CITYID: + return "vnd.android.cursor.item/vnd.revanmj.cities"; + + default: + throw new IllegalArgumentException("Unsupported URI: " + uri); + } + } + + @Override + public Uri insert(Uri uri, ContentValues contentValues) { + long rowId = db.insert(TABLE_STORMS, null, contentValues); + + if (rowId > 0) { + Uri _uri = ContentUris.withAppendedId(CONTENT_URI, rowId); + getContext().getContentResolver().notifyChange(_uri, null); + return _uri; + } + + throw new SQLException("Failed to add a city into " + uri); + } + + @Override + public int delete(Uri uri, String selection, String[] selectionArgs) { + int count = 0; + + switch (uriMatcher.match(uri)){ + case URI_CITIES: + count = db.delete(TABLE_STORMS, selection, selectionArgs); + break; + + case URI_CITYID: + String id = uri.getPathSegments().get(1); + count = db.delete(TABLE_STORMS, CITYID + " = " + id + + (!TextUtils.isEmpty(selection) ? " AND (" + selection + ')' : ""), selectionArgs); + break; + + default: + throw new IllegalArgumentException("Unknown URI " + uri); + } + + getContext().getContentResolver().notifyChange(uri, null); + return count; + } + + @Override + public int update(Uri uri, ContentValues values, String selection, String[] selectionArgs) { + int count = 0; + + switch (uriMatcher.match(uri)){ + case URI_CITIES: + count = db.update(TABLE_STORMS, values, selection, selectionArgs); + break; + + case URI_CITYID: + count = db.update(TABLE_STORMS, values, CITYID + " = " + uri.getPathSegments().get(1) + + (!TextUtils.isEmpty(selection) ? " AND (" +selection + ')' : ""), selectionArgs); + break; + + default: + throw new IllegalArgumentException("Unknown URI " + uri ); + } + getContext().getContentResolver().notifyChange(uri, null); + return count; + } + + private SQLiteDatabase db; + private static final int DATABASE_VERSION = 3; + private static final String DATABASE_NAME = "dictionary"; + private static final String TABLE_STORMS = "StormData"; + public static final String KEY_ID = "city_id"; + public static final String KEY_CITYNAME = "name"; + public static final String KEY_STORMCHANCE = "p_burzy"; + public static final String KEY_STORMTIME = "t_burzy"; + public static final String KEY_RAINTIME = "t_opadow"; + public static final String KEY_RAINCHANCE = "p_opadow"; + private static final String TABLE_CREATE = + "CREATE TABLE " + TABLE_STORMS + " ( " + + KEY_ID + " INTEGER PRIMARY KEY, " + + KEY_CITYNAME + " TEXT, "+ + KEY_STORMCHANCE + " INTEGER," + + KEY_STORMTIME + " INTEGER," + + KEY_RAINCHANCE + " INTEGER, " + + KEY_RAINTIME + " INTEGER )"; + + public static class StormDataSqlHelper extends SQLiteOpenHelper { + + public StormDataSqlHelper(Context context) { + super(context, DATABASE_NAME, null, DATABASE_VERSION); + } + + @Override + public void onCreate(SQLiteDatabase db) { + db.execSQL(TABLE_CREATE); + } + + @Override + public void onUpgrade(SQLiteDatabase db, int i, int i1) { + List cities = new LinkedList(); + + String query = "SELECT * FROM " + TABLE_STORMS; + + Cursor cursor = db.rawQuery(query, null); + + StormData city = null; + if (cursor.moveToFirst()) { + do { + city = new StormData(); + city.setCityId(Integer.parseInt(cursor.getString(0))); + city.setCityName(cursor.getString(1)); + city.setStormChance(Integer.parseInt(cursor.getString(2))); + city.setStormTime(Integer.parseInt(cursor.getString(3))); + city.setRainChance(Integer.parseInt(cursor.getString(4))); + city.setRainTime(Integer.parseInt(cursor.getString(5))); + + cities.add(city); + } while (cursor.moveToNext()); + } + + // Drop older table if existed + db.execSQL("DROP TABLE IF EXISTS StormData"); + + // create fresh table + this.onCreate(db); + + for (int j=0; j 0) + Snackbar.make(viewHolder.itemView, "Deleted city succesfully", Snackbar.LENGTH_SHORT); + } + + @Override + public void onChildDraw(Canvas c, RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder, float dX, float dY, int actionState, boolean isCurrentlyActive) { + View itemView = viewHolder.itemView; + + // not sure why, but this method get's called for viewholder that are already swiped away + if (viewHolder.getAdapterPosition() == -1) { + // not interested in those + return; + } + + // draw red background + background.setBounds(itemView.getRight() + (int) dX, itemView.getTop(), itemView.getRight(), itemView.getBottom()); + background.draw(c); + + // draw x mark + int itemHeight = itemView.getBottom() - itemView.getTop(); + int intrinsicWidth = deleteIcon.getIntrinsicWidth(); + int intrinsicHeight = deleteIcon.getIntrinsicWidth(); + + int xMarkLeft = itemView.getRight() - deleteIconMargin - intrinsicWidth; + int xMarkRight = itemView.getRight() - deleteIconMargin; + int xMarkTop = itemView.getTop() + (itemHeight - intrinsicHeight)/2; + int xMarkBottom = xMarkTop + intrinsicHeight; + deleteIcon.setBounds(xMarkLeft, xMarkTop, xMarkRight, xMarkBottom); + + deleteIcon.draw(c); + + super.onChildDraw(c, recyclerView, viewHolder, dX, dY, actionState, isCurrentlyActive); + } +} diff --git a/StormMonitor/src/main/java/pl/revanmj/stormmonitor/logic/Downloader.java b/StormMonitor/src/main/java/pl/revanmj/stormmonitor/logic/Utils.java similarity index 61% rename from StormMonitor/src/main/java/pl/revanmj/stormmonitor/logic/Downloader.java rename to StormMonitor/src/main/java/pl/revanmj/stormmonitor/logic/Utils.java index b567a11..5f054bd 100644 --- a/StormMonitor/src/main/java/pl/revanmj/stormmonitor/logic/Downloader.java +++ b/StormMonitor/src/main/java/pl/revanmj/stormmonitor/logic/Utils.java @@ -1,5 +1,7 @@ package pl.revanmj.stormmonitor.logic; +import android.content.Context; +import android.database.Cursor; import android.util.JsonReader; import java.io.InputStreamReader; @@ -9,15 +11,38 @@ import java.util.ArrayList; import java.util.List; +import pl.revanmj.stormmonitor.data.StormDataProvider; import pl.revanmj.stormmonitor.model.DownloadResult; import pl.revanmj.stormmonitor.model.StormData; /** - * Created by Student on 10.07.13. + * Created by revanmj on 10.07.2013. */ -public class Downloader { + +public class Utils { private static String BASE_URL = "http://antistorm.eu/webservice.php?id="; + static public List getAllData(Context context){ + String[] projection = {StormDataProvider.KEY_ID, StormDataProvider.KEY_CITYNAME, StormDataProvider.KEY_STORMCHANCE, StormDataProvider.KEY_STORMTIME, StormDataProvider.KEY_RAINCHANCE, StormDataProvider.KEY_RAINTIME}; + Cursor c = context.getContentResolver().query(StormDataProvider.CONTENT_URI, projection, null, null, null); + + if (c != null) { + List cities = new ArrayList<>(); + while (c.moveToNext()) { + StormData tmp = new StormData(); + tmp.setCityId(c.getInt(StormDataProvider.CITYID)); + tmp.setCityName(c.getString(StormDataProvider.CITYNAME)); + tmp.setStormChance(c.getInt(StormDataProvider.STORMCHANCE)); + tmp.setStormTime(c.getInt(StormDataProvider.STORMTIME)); + tmp.setRainChance(c.getInt(StormDataProvider.RAINCHANCE)); + tmp.setRainTime(c.getInt(StormDataProvider.RAINTIME)); + cities.add(tmp); + } + return cities; + } + + return new ArrayList<>(); + } static public DownloadResult getStormData(List list) { int resultCode = 1; @@ -27,7 +52,7 @@ static public DownloadResult getStormData(List list) { for (StormData city : list) { try { - con = (HttpURLConnection) (new URL(BASE_URL + city.getMiasto_id())).openConnection(); + con = (HttpURLConnection) (new URL(BASE_URL + city.getCityId())).openConnection(); con.setRequestMethod("GET"); con.setConnectTimeout(3000); con.connect(); @@ -37,22 +62,22 @@ static public DownloadResult getStormData(List list) { // Setting city database id StormData data = new StormData(); - data.setMiasto_id(city.getMiasto_id()); + data.setCityId(city.getCityId()); // Parsing received data into StormData obejct reader.beginObject(); while (reader.hasNext()) { String name = reader.nextName(); if (name.equals("m")) - data.setMiasto(reader.nextString()); + data.setCityName(reader.nextString()); else if (name.equals("p_b")) - data.setP_burzy(reader.nextInt()); + data.setStormChance(reader.nextInt()); else if (name.equals("t_b")) - data.setT_burzy(reader.nextInt()); + data.setStormTime(reader.nextInt()); else if (name.equals("p_o")) - data.setP_opadow(reader.nextInt()); + data.setRainChance(reader.nextInt()); else if (name.equals("t_o")) - data.setT_opadow(reader.nextInt()); + data.setRainTime(reader.nextInt()); else { reader.skipValue(); } diff --git a/StormMonitor/src/main/java/pl/revanmj/stormmonitor/model/DownloadResult.java b/StormMonitor/src/main/java/pl/revanmj/stormmonitor/model/DownloadResult.java index 328aca9..d934849 100644 --- a/StormMonitor/src/main/java/pl/revanmj/stormmonitor/model/DownloadResult.java +++ b/StormMonitor/src/main/java/pl/revanmj/stormmonitor/model/DownloadResult.java @@ -5,6 +5,7 @@ /** * Created by revanmj on 06.09.2015. */ + public class DownloadResult { List cities = null; int resultCode = -1; diff --git a/StormMonitor/src/main/java/pl/revanmj/stormmonitor/model/StormData.java b/StormMonitor/src/main/java/pl/revanmj/stormmonitor/model/StormData.java index a1913d3..4d3bdf7 100644 --- a/StormMonitor/src/main/java/pl/revanmj/stormmonitor/model/StormData.java +++ b/StormMonitor/src/main/java/pl/revanmj/stormmonitor/model/StormData.java @@ -3,39 +3,40 @@ import java.io.Serializable; /** - * Created by Student on 10.07.13. + * Created by revanmj on 10.07.2013. */ + public class StormData implements Serializable { - private int miasto_id; - private String miasto; - private int p_burzy; - private int t_burzy; - private int p_opadow; - private int t_opadow; + private int cityId; + private String cityName; + private int stormChance; + private int stormTime; + private int rainChance; + private int rainTime; private boolean error; - public String getMiasto() { - return miasto; + public String getCityName() { + return cityName; } - public void setMiasto(String miasto) { - this.miasto = miasto; + public void setCityName(String cityName) { + this.cityName = cityName; } - public int getP_burzy() { - return p_burzy; + public int getStormChance() { + return stormChance; } - public void setP_burzy(int p_burzy) { - this.p_burzy = p_burzy; + public void setStormChance(int stormChance) { + this.stormChance = stormChance; } - public int getT_burzy() { - return t_burzy; + public int getStormTime() { + return stormTime; } - public void setT_burzy(int t_burzy) { - this.t_burzy = t_burzy; + public void setStormTime(int stormTime) { + this.stormTime = stormTime; } public boolean isError() { @@ -46,28 +47,28 @@ public void setError(boolean error) { this.error = error; } - public int getMiasto_id() { - return miasto_id; + public int getCityId() { + return cityId; } - public void setMiasto_id(int miasto_id) { - this.miasto_id = miasto_id; + public void setCityId(int cityId) { + this.cityId = cityId; } - public int getT_opadow() { - return t_opadow; + public int getRainTime() { + return rainTime; } - public void setT_opadow(int t_opadow) { - this.t_opadow = t_opadow; + public void setRainTime(int rainTime) { + this.rainTime = rainTime; } - public int getP_opadow() { - return p_opadow; + public int getRainChance() { + return rainChance; } - public void setP_opadow(int p_opadow) { - this.p_opadow = p_opadow; + public void setRainChance(int rainChance) { + this.rainChance = rainChance; } } diff --git a/StormMonitor/src/main/java/pl/revanmj/stormmonitor/sql/StormOpenHelper.java b/StormMonitor/src/main/java/pl/revanmj/stormmonitor/sql/StormOpenHelper.java deleted file mode 100644 index b77350c..0000000 --- a/StormMonitor/src/main/java/pl/revanmj/stormmonitor/sql/StormOpenHelper.java +++ /dev/null @@ -1,196 +0,0 @@ -package pl.revanmj.stormmonitor.sql; - -import android.content.ContentValues; -import android.content.Context; -import android.database.Cursor; -import android.database.sqlite.SQLiteDatabase; -import android.database.sqlite.SQLiteOpenHelper; -import android.util.Log; - -import pl.revanmj.stormmonitor.model.StormData; - -import java.util.LinkedList; -import java.util.List; - -/** - * Created by revanmj on 26.12.2013. - */ -public class StormOpenHelper extends SQLiteOpenHelper { - private static final int DATABASE_VERSION = 3; - private static final String DATABASE_NAME = "dictionary"; - private static final String TABLE_STORMS = "StormData"; - private static final String KEY_ID = "city_id"; - private static final String KEY_NAME = "name"; - private static final String KEY_PBURZY = "p_burzy"; - private static final String KEY_TBURZY = "t_burzy"; - private static final String KEY_TOPADOW = "t_opadow"; - private static final String KEY_POPADOW = "p_opadow"; - private static final String TABLE_CREATE = - "CREATE TABLE " + TABLE_STORMS + " ( " + - KEY_ID + " INTEGER PRIMARY KEY, " + - KEY_NAME + " TEXT, "+ - KEY_PBURZY + " INTEGER," + - KEY_TBURZY + " INTEGER," + - KEY_POPADOW + " INTEGER, " + - KEY_TOPADOW + " INTEGER )"; - - public StormOpenHelper(Context context) { - super(context, DATABASE_NAME, null, DATABASE_VERSION); - } - - @Override - public void onCreate(SQLiteDatabase db) { - db.execSQL(TABLE_CREATE); - } - - @Override - public void onUpgrade(SQLiteDatabase db, int i, int i2) { - List cities = new LinkedList(); - - String query = "SELECT * FROM " + TABLE_STORMS; - - Cursor cursor = db.rawQuery(query, null); - - StormData city = null; - if (cursor.moveToFirst()) { - do { - city = new StormData(); - city.setMiasto_id(Integer.parseInt(cursor.getString(0))); - city.setMiasto(cursor.getString(1)); - city.setP_burzy(Integer.parseInt(cursor.getString(2))); - city.setT_burzy(Integer.parseInt(cursor.getString(3))); - city.setP_opadow(Integer.parseInt(cursor.getString(4))); - city.setT_opadow(Integer.parseInt(cursor.getString(5))); - - cities.add(city); - } while (cursor.moveToNext()); - } - - // Drop older books table if existed - db.execSQL("DROP TABLE IF EXISTS StormData"); - - // create fresh books table - this.onCreate(db); - - for (int j=0; j keys = column names/ values = column values - } - - // 4. close - db.close(); - } - - public void addCity(StormData city){ - //for logging - Log.d("addCity", city.toString()); - - // 1. get reference to writable DB - SQLiteDatabase db = this.getWritableDatabase(); - - // 2. create ContentValues to add key "column"/value - ContentValues values = new ContentValues(); - values.put(KEY_ID, city.getMiasto_id()); - values.put(KEY_NAME, city.getMiasto()); - values.put(KEY_PBURZY, city.getP_burzy()); - values.put(KEY_TBURZY, city.getT_burzy()); - values.put(KEY_POPADOW, city.getP_opadow()); - values.put(KEY_TOPADOW, city.getT_opadow()); - - // 3. insert - db.insert(TABLE_STORMS, // table - null, //nullColumnHack - values); // key/value -> keys = column names/ values = column values - - // 4. close - db.close(); - } - - public List getAllCities() { - List cities = new LinkedList(); - - // 1. build the query - String query = "SELECT * FROM " + TABLE_STORMS; - - // 2. get reference to writable DB - SQLiteDatabase db = this.getWritableDatabase(); - Cursor cursor = db.rawQuery(query, null); - - // 3. go over each row, build book and add it to list - StormData city = null; - if (cursor.moveToFirst()) { - do { - city = new StormData(); - city.setMiasto_id(Integer.parseInt(cursor.getString(0))); - city.setMiasto(cursor.getString(1)); - city.setP_burzy(Integer.parseInt(cursor.getString(2))); - city.setT_burzy(Integer.parseInt(cursor.getString(3))); - city.setP_opadow(Integer.parseInt(cursor.getString(4))); - city.setT_opadow(Integer.parseInt(cursor.getString(5))); - - // Add book to books - cities.add(city); - } while (cursor.moveToNext()); - } - - Log.d("getAllCities()", cities.toString()); - - // return books - return cities; - } - - public int updateCity(StormData city) { - - // 1. get reference to writable DB - SQLiteDatabase db = this.getWritableDatabase(); - - // 2. create ContentValues to add key "column"/value - ContentValues values = new ContentValues(); - values.put(KEY_NAME, city.getMiasto()); - values.put(KEY_PBURZY, city.getP_burzy()); - values.put(KEY_TBURZY, city.getT_burzy()); - values.put(KEY_POPADOW, city.getP_opadow()); - values.put(KEY_TOPADOW, city.getT_opadow()); - - // 3. updating row - int i = db.update(TABLE_STORMS, //table - values, // column/value - KEY_ID + " = ?", // selections - new String[] { String.valueOf(city.getMiasto_id()) }); //selection args - - // 4. close - db.close(); - - return i; - - } - - public void deleteCity(StormData city) { - - // 1. get reference to writable DB - SQLiteDatabase db = this.getWritableDatabase(); - - // 2. delete - db.delete(TABLE_STORMS, //table name - KEY_ID+" = ?", // selections - new String[] { String.valueOf(city.getMiasto_id()) }); //selections args - - // 3. close - db.close(); - - //log - Log.d("deleteCity", city.toString()); - - } - -} diff --git a/StormMonitor/src/main/res/drawable-hdpi/header_bg_widget.9.png b/StormMonitor/src/main/res/drawable-hdpi/header_bg_widget.9.png index 6216ba3..19d6c7a 100644 Binary files a/StormMonitor/src/main/res/drawable-hdpi/header_bg_widget.9.png and b/StormMonitor/src/main/res/drawable-hdpi/header_bg_widget.9.png differ diff --git a/StormMonitor/src/main/res/drawable-mdpi/header_bg_widget.9.png b/StormMonitor/src/main/res/drawable-mdpi/header_bg_widget.9.png index 500cc4c..9ed24fb 100644 Binary files a/StormMonitor/src/main/res/drawable-mdpi/header_bg_widget.9.png and b/StormMonitor/src/main/res/drawable-mdpi/header_bg_widget.9.png differ diff --git a/StormMonitor/src/main/res/drawable-xhdpi/header_bg_widget.9.png b/StormMonitor/src/main/res/drawable-xhdpi/header_bg_widget.9.png index fa41141..921e3d5 100644 Binary files a/StormMonitor/src/main/res/drawable-xhdpi/header_bg_widget.9.png and b/StormMonitor/src/main/res/drawable-xhdpi/header_bg_widget.9.png differ diff --git a/StormMonitor/src/main/res/drawable-xhdpi/widget_preview.png b/StormMonitor/src/main/res/drawable-xhdpi/widget_preview.png index 85c8f30..e4d1190 100644 Binary files a/StormMonitor/src/main/res/drawable-xhdpi/widget_preview.png and b/StormMonitor/src/main/res/drawable-xhdpi/widget_preview.png differ diff --git a/StormMonitor/src/main/res/drawable/ic_delete.xml b/StormMonitor/src/main/res/drawable/ic_delete.xml new file mode 100644 index 0000000..6d70645 --- /dev/null +++ b/StormMonitor/src/main/res/drawable/ic_delete.xml @@ -0,0 +1,9 @@ + + + \ No newline at end of file diff --git a/StormMonitor/src/main/res/layout/activity_main.xml b/StormMonitor/src/main/res/layout/activity_main.xml index 6b2ebb9..8e76494 100644 --- a/StormMonitor/src/main/res/layout/activity_main.xml +++ b/StormMonitor/src/main/res/layout/activity_main.xml @@ -1,31 +1,46 @@ - + android:fitsSystemWindows="true" + tools:context="pl.revanmj.stormmonitor.MainActivity"> + + + + + + - + - + + + + diff --git a/StormMonitor/src/main/res/layout/cities_widget.xml b/StormMonitor/src/main/res/layout/cities_widget.xml index ca5dfbd..80feb9c 100644 --- a/StormMonitor/src/main/res/layout/cities_widget.xml +++ b/StormMonitor/src/main/res/layout/cities_widget.xml @@ -35,7 +35,7 @@ android:layout_height="wrap_content" android:textAppearance="?android:attr/textAppearanceMedium" android:text="@string/app_name" - android:textColor="#333333" + android:textColor="#ffffff" /> diff --git a/StormMonitor/src/main/res/layout/row_listview.xml b/StormMonitor/src/main/res/layout/row_listview.xml index 08c4cc4..0fd8208 100644 --- a/StormMonitor/src/main/res/layout/row_listview.xml +++ b/StormMonitor/src/main/res/layout/row_listview.xml @@ -2,7 +2,8 @@ + android:layout_height="match_parent" + android:foreground="?selectableItemBackground"> - - \ No newline at end of file diff --git a/StormMonitor/src/main/res/menu/context.xml b/StormMonitor/src/main/res/menu/context.xml deleted file mode 100644 index 5ec2946..0000000 --- a/StormMonitor/src/main/res/menu/context.xml +++ /dev/null @@ -1,7 +0,0 @@ - - - - - \ No newline at end of file diff --git a/StormMonitor/src/main/res/menu/main.xml b/StormMonitor/src/main/res/menu/main.xml index 8380697..1f56904 100644 --- a/StormMonitor/src/main/res/menu/main.xml +++ b/StormMonitor/src/main/res/menu/main.xml @@ -5,11 +5,6 @@ android:icon="@drawable/ic_add_white_24dp" android:orderInCategory="1" app:showAsAction="ifRoom" /> - > + + + diff --git a/StormMonitor/src/main/res/values/dimens.xml b/StormMonitor/src/main/res/values/dimens.xml index 52b187a..36e0e87 100644 --- a/StormMonitor/src/main/res/values/dimens.xml +++ b/StormMonitor/src/main/res/values/dimens.xml @@ -5,5 +5,7 @@ 16dp 16dp 8dp + 16dp + 16dp diff --git a/StormMonitor/src/main/res/values/strings.xml b/StormMonitor/src/main/res/values/strings.xml index 385f965..6bff6f0 100644 --- a/StormMonitor/src/main/res/values/strings.xml +++ b/StormMonitor/src/main/res/values/strings.xml @@ -4,14 +4,14 @@ Storm Monitor Mapa burz Mapa opadów - Dodaj miasto - Dodaj miasto przez GPS + Dodaj cityName + Dodaj cityName przez GPS O programie Usuń - Usunąć miasto? + Usunąć cityName? Szczegóły Błąd! - To miasto jest już dodane + To cityName jest już dodane Twojego miasta nie ma w bazie Pobieranie mapy nie powiodło się. Pobieranie nie powiodło się. @@ -28,7 +28,7 @@ Przełącz na mapę burzową Przełącz na mapę opadów Podaj nazwę miasta - Dodaj miasto + Dodaj cityName Szukaj Nie znaleziono miast o podanej nazwie Aktualizuj diff --git a/StormMonitor/src/main/res/values/styles.xml b/StormMonitor/src/main/res/values/styles.xml index 1d2b98b..52da6ee 100644 --- a/StormMonitor/src/main/res/values/styles.xml +++ b/StormMonitor/src/main/res/values/styles.xml @@ -1,7 +1,7 @@ - + + +