Commit dccb5271 authored by Joey Rizzoli's avatar Joey Rizzoli
Browse files

Refactor cyanogenmod -> lineageos



Change-Id: Iec5619c8b7182bde4b3e3fe815fff50332c2dc4f
Signed-off-by: default avatarJoey Rizzoli <joey@lineageos.org>
parent 9d018970
......@@ -5,7 +5,7 @@ android {
buildToolsVersion "25.0.2"
defaultConfig {
applicationId "org.cyanogenmod.openweathermapprovider"
applicationId "org.lineageos.openweathermapprovider"
minSdkVersion 23
targetSdkVersion 25
versionCode 1
......
......@@ -14,7 +14,7 @@
limitations under the License.
-->
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="org.cyanogenmod.openweathermapprovider">
package="org.lineageos.openweathermapprovider">
<uses-permission android:name="cyanogenmod.permission.ACCESS_WEATHER_MANAGER" />
<uses-permission android:name="android.permission.INTERNET" />
......@@ -28,7 +28,7 @@
android:theme="@style/AppTheme">
<service
android:name=".OpenWeatherMapProviderService"
android:name="org.lineageos.openweathermapprovider.OpenWeatherMapProviderService"
android:label="@string/app_name"
android:exported="true"
android:permission="cyanogenmod.permission.BIND_WEATHER_PROVIDER_SERVICE">
......@@ -40,7 +40,7 @@
android:resource="@xml/openweathermap" />
</service>
<activity android:name=".SettingsActivity"
<activity android:name="org.lineageos.openweathermapprovider.SettingsActivity"
android:label="@string/app_name"
android:exported="true" />
</application>
......
......@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.cyanogenmod.openweathermapprovider;
package org.lineageos.openweathermapprovider;
import android.content.SharedPreferences;
import android.location.Location;
......@@ -22,7 +22,8 @@ import android.os.AsyncTask;
import android.os.SystemClock;
import android.preference.PreferenceManager;
import org.cyanogenmod.openweathermapprovider.openweathermap.OpenWeatherMapService;
import org.lineageos.openweathermapprovider.openweathermap.OpenWeatherMapService;
import org.lineageos.openweathermapprovider.utils.Logging;
import java.util.HashMap;
import java.util.List;
......@@ -36,9 +37,6 @@ import cyanogenmod.weatherservice.ServiceRequest;
import cyanogenmod.weatherservice.ServiceRequestResult;
import cyanogenmod.weatherservice.WeatherProviderService;
import static org.cyanogenmod.openweathermapprovider.utils.Logging.logd;
import static org.cyanogenmod.openweathermapprovider.utils.Logging.logw;
public class OpenWeatherMapProviderService extends WeatherProviderService
implements SharedPreferences.OnSharedPreferenceChangeListener {
......@@ -85,7 +83,7 @@ public class OpenWeatherMapProviderService extends WeatherProviderService
protected void onRequestSubmitted(ServiceRequest request) {
RequestInfo requestInfo = request.getRequestInfo();
int requestType = requestInfo.getRequestType();
logd("Received request type " + requestType);
Logging.logd("Received request type " + requestType);
if (((requestType == RequestInfo.TYPE_WEATHER_BY_GEO_LOCATION_REQ &&
isSameGeoLocation(requestInfo.getLocation(), mLastLocation))
......@@ -138,7 +136,7 @@ public class OpenWeatherMapProviderService extends WeatherProviderService
}
return;
default:
logw("Received unknown request type "
Logging.logw("Received unknown request type "
+ request.getRequestInfo().getRequestType());
break;
}
......@@ -147,7 +145,7 @@ public class OpenWeatherMapProviderService extends WeatherProviderService
@Override
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
if (key.equals(API_KEY)) {
logd("API key has changed");
Logging.logd("API key has changed");
final String mApiKey = sharedPreferences.getString(key, null);
mOpenWeatherMapService.setApiKey(mApiKey);
}
......@@ -165,13 +163,13 @@ public class OpenWeatherMapProviderService extends WeatherProviderService
private boolean isSameGeoLocation(Location newLocation, Location oldLocation) {
if (newLocation == null || oldLocation == null) return false;
float distance = newLocation.distanceTo(oldLocation);
logd("Distance between locations " + distance);
Logging.logd("Distance between locations " + distance);
return (distance < LOCATION_DISTANCE_METERS_THRESHOLD);
}
private boolean wasRequestSubmittedTooSoon() {
final long now = SystemClock.elapsedRealtime();
logd("Now " + now + " last request " + mLastRequestTimestamp);
Logging.logd("Now " + now + " last request " + mLastRequestTimestamp);
return (mLastRequestTimestamp + REQUEST_THRESHOLD > now);
}
......@@ -203,7 +201,7 @@ public class OpenWeatherMapProviderService extends WeatherProviderService
}
} else {
// We don't know how to handle any other type of request
logw("Received unknown request type "+ requestType);
Logging.logw("Received unknown request type "+ requestType);
return null;
}
}
......@@ -211,10 +209,10 @@ public class OpenWeatherMapProviderService extends WeatherProviderService
@Override
protected void onPostExecute(WeatherInfo weatherInfo) {
if (weatherInfo == null) {
logd("Received null weather info, failing request");
Logging.logd("Received null weather info, failing request");
mRequest.fail();
} else {
logd(weatherInfo.toString());
Logging.logd(weatherInfo.toString());
ServiceRequestResult result = new ServiceRequestResult.Builder(weatherInfo).build();
mRequest.complete(result);
if (mRequest.getRequestInfo().getRequestType()
......@@ -243,7 +241,7 @@ public class OpenWeatherMapProviderService extends WeatherProviderService
protected List<WeatherLocation> doInBackground(Void... params) {
RequestInfo requestInfo = mRequest.getRequestInfo();
if (requestInfo.getRequestType() != RequestInfo.TYPE_LOOKUP_CITY_NAME_REQ) {
logw("Received unsupported request type " + requestInfo.getRequestType());
Logging.logw("Received unsupported request type " + requestInfo.getRequestType());
return null;
}
try {
......@@ -258,7 +256,7 @@ public class OpenWeatherMapProviderService extends WeatherProviderService
protected void onPostExecute(List<WeatherLocation> locations) {
if (locations != null) {
for (WeatherLocation location : locations) {
logd(location.toString());
Logging.logd(location.toString());
}
ServiceRequestResult request = new ServiceRequestResult.Builder(locations).build();
mRequest.complete(request);
......
......@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.cyanogenmod.openweathermapprovider;
package org.lineageos.openweathermapprovider;
import android.app.Activity;
import android.content.Context;
......@@ -49,7 +49,7 @@ public class SettingsActivity extends Activity {
@Override
public void onCreate(Bundle savedInstance) {
super.onCreate(savedInstance);
addPreferencesFromResource(R.xml.preferences);
addPreferencesFromResource(org.lineageos.openweathermapprovider.R.xml.preferences);
mApiKeyPreference = (EditTextPreference) findPreference(API_KEY);
SharedPreferences sharedPreferences
......@@ -58,12 +58,12 @@ public class SettingsActivity extends Activity {
try {
//lookup the value state
String[] stateEntries
= getResources().getStringArray(R.array.api_key_states_entries);
= getResources().getStringArray(org.lineageos.openweathermapprovider.R.array.api_key_states_entries);
String state = stateEntries[apiKeyVerificationState];
mApiKeyPreference.setSummary(state);
} catch (IndexOutOfBoundsException e) {
mApiKeyPreference.setSummary(getString(R.string.prefscreen_api_key_summary,
getString(R.string.app_name)));
mApiKeyPreference.setSummary(getString(org.lineageos.openweathermapprovider.R.string.prefscreen_api_key_summary,
getString(org.lineageos.openweathermapprovider.R.string.app_name)));
}
}
......@@ -75,8 +75,8 @@ public class SettingsActivity extends Activity {
SharedPreferences sp = getPreferenceManager().getSharedPreferences();
String apiKey = sp.getString(API_KEY, null);
if (apiKey == null || apiKey.equals("")) {
Toast.makeText(context, getString(R.string.api_key_not_set_message,
getString(R.string.app_name)), Toast.LENGTH_LONG).show();
Toast.makeText(context, getString(org.lineageos.openweathermapprovider.R.string.api_key_not_set_message,
getString(org.lineageos.openweathermapprovider.R.string.app_name)), Toast.LENGTH_LONG).show();
}
mApiKeyPreference.setOnPreferenceChangeListener(this);
}
......@@ -91,8 +91,8 @@ public class SettingsActivity extends Activity {
sharedPreferences.edit().putInt(API_KEY_VERIFIED_STATE,
API_KEY_PENDING_VERIFICATION).apply();
mApiKeyPreference.setSummary(getResources().getStringArray(
R.array.api_key_states_entries)[API_KEY_PENDING_VERIFICATION]);
Toast.makeText(getActivity(), R.string.api_key_changed_verification_warning,
org.lineageos.openweathermapprovider.R.array.api_key_states_entries)[API_KEY_PENDING_VERIFICATION]);
Toast.makeText(getActivity(), org.lineageos.openweathermapprovider.R.string.api_key_changed_verification_warning,
Toast.LENGTH_LONG).show();
return true;
}
......
......@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.cyanogenmod.openweathermapprovider.openweathermap;
package org.lineageos.openweathermapprovider.openweathermap;
import com.google.gson.annotations.SerializedName;
......
......@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.cyanogenmod.openweathermapprovider.openweathermap;
package org.lineageos.openweathermapprovider.openweathermap;
import com.google.gson.annotations.SerializedName;
......
......@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.cyanogenmod.openweathermapprovider.openweathermap;
package org.lineageos.openweathermapprovider.openweathermap;
import com.google.gson.annotations.SerializedName;
......
......@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.cyanogenmod.openweathermapprovider.openweathermap;
package org.lineageos.openweathermapprovider.openweathermap;
import retrofit2.Call;
import retrofit2.http.GET;
......
......@@ -14,12 +14,14 @@
* limitations under the License.
*/
package org.cyanogenmod.openweathermapprovider.openweathermap;
package org.lineageos.openweathermapprovider.openweathermap;
import android.content.Context;
import android.location.Location;
import android.text.TextUtils;
import org.lineageos.openweathermapprovider.utils.Logging;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
......@@ -38,8 +40,6 @@ import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;
import static org.cyanogenmod.openweathermapprovider.utils.Logging.logd;
public class OpenWeatherMapService {
private static final String RESULT_FORMAT = "json";
......@@ -88,7 +88,7 @@ public class OpenWeatherMapService {
RESULT_FORMAT, units, language, mApiKey);
Response<CurrentWeatherResponse> currentWeatherResponse;
try {
logd(weatherResponseCall.request().toString());
Logging.logd(weatherResponseCall.request().toString());
currentWeatherResponse = weatherResponseCall.execute();
} catch (IOException e) {
//An error occurred while talking to the server
......@@ -103,12 +103,12 @@ public class OpenWeatherMapService {
RESULT_FORMAT, units, language, FORECAST_DAYS, mApiKey);
ForecastResponse forecastResponse = null;
try {
logd(forecastResponseCall.request().toString());
Logging.logd(forecastResponseCall.request().toString());
Response<ForecastResponse> r = forecastResponseCall.execute();
if (r.code() == 200) forecastResponse = r.body();
} catch (IOException e) {
//this is an error we can live with
logd("IOException while requesting forecast " + e);
Logging.logd("IOException while requesting forecast " + e);
}
return processWeatherResponse(currentWeatherResponse.body(), forecastResponse,
tempUnit);
......@@ -136,11 +136,11 @@ public class OpenWeatherMapService {
location.getLongitude(), RESULT_FORMAT, units, language, mApiKey);
Response<CurrentWeatherResponse> currentWeatherResponse;
try {
logd(weatherResponseCall.request().toString());
Logging.logd(weatherResponseCall.request().toString());
currentWeatherResponse = weatherResponseCall.execute();
} catch (IOException e) {
//An error occurred while talking to the server
logd("IOException while requesting weather " + e);
Logging.logd("IOException while requesting weather " + e);
return null;
}
......@@ -152,12 +152,12 @@ public class OpenWeatherMapService {
location.getLongitude(), RESULT_FORMAT, units, language, FORECAST_DAYS, mApiKey);
ForecastResponse forecastResponse = null;
try {
logd(forecastResponseCall.request().toString());
Logging.logd(forecastResponseCall.request().toString());
Response<ForecastResponse> r = forecastResponseCall.execute();
if (r.code() == 200) forecastResponse = r.body();
} catch (IOException e) {
//this is an error we can live with
logd("IOException while requesting forecast " + e);
Logging.logd("IOException while requesting forecast " + e);
}
return processWeatherResponse(currentWeatherResponse.body(), forecastResponse,
tempUnit);
......@@ -251,10 +251,10 @@ public class OpenWeatherMapService {
Response<LookupCityResponse> lookupResponse;
try {
logd(lookupCityCall.request().toString());
Logging.logd(lookupCityCall.request().toString());
lookupResponse = lookupCityCall.execute();
} catch (IOException e) {
logd("IOException while looking up city name " + e);
Logging.logd("IOException while looking up city name " + e);
//Return empty list to prevent NPE
return new ArrayList<>();
}
......
......@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.cyanogenmod.openweathermapprovider.utils;
package org.lineageos.openweathermapprovider.utils;
import android.util.Log;
......
......@@ -15,4 +15,4 @@
limitations under the License.
-->
<weather-provider-service xmlns:android="http://schemas.android.com/apk/res/android"
android:settingsActivity="org.cyanogenmod.openweathermapprovider.SettingsActivity"/>
\ No newline at end of file
android:settingsActivity="org.lineageos.openweathermapprovider.SettingsActivity"/>
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment