Skip to content

Commit

Permalink
Merge pull request #169 from camarm-dev/dev
Browse files Browse the repository at this point in the history
Version 1.2.0 with patches for #166, #167, #168 and #170
  • Loading branch information
camarm-dev authored Jun 15, 2024
2 parents ab4e57c + 7edc573 commit 435528e
Show file tree
Hide file tree
Showing 100 changed files with 199,332 additions and 372 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@
/docs/_site/
/data/remede.db
/data/remede-less.db
/data/remede.*.db
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ La version `1.2.0`, nom de code `Brown Sheep` inclue les nouvelles fonctionnalit
- [x] Nouvelle navigation **encore plus agréable**.
- [x] Actions natives quand **un mot est sélectionné** n'importe où dans votre téléphone !
- [x] Widget pour un accès **plus rapide**.
- [x] **Base révisée** avec +340 000 mots !
- [ ] Téléchargeable sur le **Play Store** !

## Télécharger
Expand Down
4 changes: 2 additions & 2 deletions app/android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ android {
applicationId "com.camarm.remede"
minSdkVersion rootProject.ext.minSdkVersion
targetSdkVersion rootProject.ext.targetSdkVersion
versionCode 1202
versionName '1.2.0-beta.2 — Brown Sheep, beta rev 2'
versionCode 120
versionName '1.2.0 — Brown Sheep'
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
aaptOptions {
// Files and dirs to omit from the packaged assets dir, modified to accommodate modern web apps.
Expand Down
4 changes: 2 additions & 2 deletions app/android/app/release/output-metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
"type": "SINGLE",
"filters": [],
"attributes": [],
"versionCode": 1202,
"versionName": "1.2.0-beta.2 — Brown Sheep, beta rev 2",
"versionCode": 120,
"versionName": "1.2.0 — Brown Sheep",
"outputFile": "app-release.apk"
}
],
Expand Down
16 changes: 16 additions & 0 deletions app/android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,21 @@
android:supportsRtl="true"
android:theme="@style/AppTheme"
android:usesCleartextTraffic="true">
<receiver
android:name=".RemedeWordOfDayWidget"
android:exported="false">
<intent-filter>
<action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
</intent-filter>
<intent-filter>
<action android:name="com.camarm.remede.action.OPEN_WORD_OF_DAY" />
</intent-filter>


<meta-data
android:name="android.appwidget.provider"
android:resource="@xml/remede_word_of_day_widget_info" />
</receiver>
<receiver
android:name=".RemedeSearchbarWidget"
android:exported="false">
Expand All @@ -23,6 +38,7 @@
<intent-filter>
<action android:name="com.camarm.remede.action.OPEN_SEARCHBAR" />
</intent-filter>

<meta-data
android:name="android.appwidget.provider"
android:resource="@xml/remede_searchbar_info" />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
package com.camarm.remede;

import android.app.PendingIntent;
import android.appwidget.AppWidgetManager;
import android.appwidget.AppWidgetProvider;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.StrictMode;
import android.widget.RemoteViews;

import org.json.JSONException;
import org.json.JSONObject;

import java.io.IOException;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.Scanner;

/**
* Implementation of App Widget functionality.
*/
public class RemedeWordOfDayWidget extends AppWidgetProvider {

public static String CLICK_ACTION = "com.camarm.remede.action.OPEN_WORD_OF_DAY";
public static String DEFAULT_WORD_JSON = "{}";

private static JSONObject getJsonResponse(URL url) throws JSONException, IOException {
String plain = getPlainResponse(url);
return new JSONObject(plain);
}

private static String getPlainResponse(URL url) throws IOException {
String inline = "";
Scanner scanner = new Scanner(url.openStream());
while (scanner.hasNext()) {
inline += scanner.nextLine();
}
return inline;
}

public static JSONObject getWordDocument(String word) throws JSONException, IOException {
URL getDocumentUrl = new URL("https://api-remede.camarm.fr/word/" + word);
return getJsonResponse(getDocumentUrl);
}

public static String getWordOfDay() throws IOException, JSONException {
URL getWordUrl = new URL("https://api-remede.camarm.fr/word-of-day");

HttpURLConnection wordConnection = (HttpURLConnection) getWordUrl.openConnection();
wordConnection.setRequestMethod("GET");
wordConnection.connect();

if (wordConnection.getResponseCode() == 200) {
return getPlainResponse(getWordUrl);
} else {
throw new IOException();
}
}


static void updateAppWidget(Context context, AppWidgetManager appWidgetManager,
int appWidgetId) {

StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();

StrictMode.setThreadPolicy(policy);

// Construct the RemoteViews object
RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.remede_word_of_day_widget);

// Get word of day
String word;
try {
word = getWordOfDay().replaceAll("\"", "");
} catch (JSONException | IOException e) {
word = "remède";
}

JSONObject wordDocument;

String nature;
String phoneme;
String definition;
try {
wordDocument = getWordDocument(word);
nature = wordDocument.getJSONArray("definitions").getJSONObject(0).getString("classe");
phoneme = wordDocument.getString("ipa");
definition = wordDocument.getJSONArray("definitions").getJSONObject(0).getJSONObject("explications").getString("1");
definition = definition.replaceAll("<[^>]*>", "");
if (definition.length() > 100) {
definition = definition.substring(0, 90) + "...";
}
} catch (JSONException | IOException e) {
nature = "Nom propre";
phoneme = "/ʁəmɛd/";
definition = "(Informatique) Dictionnaire français, open source et gratuit qui a pour objectif de remplacer Antidote.";
}

// Update text on widget
String capitalizedWord = word.substring(0, 1).toUpperCase() + word.substring(1);
views.setTextViewText(R.id.wodwidget_word, capitalizedWord);
views.setTextViewText(R.id.wodwidget_nature, nature);
views.setTextViewText(R.id.wodwidget_phoneme, phoneme);
views.setTextViewText(R.id.wodwidget_definition, definition);

// Handle clicks
Intent intent = new Intent(context, RemedeWordOfDayWidget.class).setAction(CLICK_ACTION).setData(Uri.parse(context.getResources().getString(R.string.custom_url_scheme) + "://dictionnaire/" + word));
PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
views.setOnClickPendingIntent(R.id.container, pendingIntent);

// Instruct the widget manager to update the widget
appWidgetManager.updateAppWidget(appWidgetId, views);
}

@Override
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
// There may be multiple widgets active, so update all of them
for (int appWidgetId : appWidgetIds) {
updateAppWidget(context, appWidgetManager, appWidgetId);
}
}

@Override
public void onEnabled(Context context) {
// Enter relevant functionality for when the first widget is created
}

@Override
public void onDisabled(Context context) {
// Enter relevant functionality for when the last widget is disabled
}

@Override
public void onReceive(Context context, Intent intent) {
super.onReceive(context, intent);
if (CLICK_ACTION.equals(intent.getAction())) {
Intent searchbarIntent = new Intent(context, MainActivity.class)
.setData(intent.getData())
.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
context.startActivity(searchbarIntent);
}
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 10 additions & 0 deletions app/android/app/src/main/res/drawable/rounded.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<corners
android:radius="15dp" />
<solid android:color="@color/background"/>
<size
android:height="110dp"
android:width="250dp" />
</shape>
Binary file not shown.
Binary file not shown.
127 changes: 127 additions & 0 deletions app/android/app/src/main/res/layout/remede_word_of_day_widget.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
style="@style/Widget.Android.AppWidget.Container"
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/transparent"
android:theme="@style/AppTheme.AppWidgetContainer">

<LinearLayout
android:background="@drawable/rounded"
style="@style/Widget.Android.AppWidget.InnerView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:orientation="vertical">

<LinearLayout
style="@style/Widget.Android.AppWidget.InnerView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:layout_margin="0dp"
android:layout_marginBottom="0dp"
android:background="@color/background"
android:orientation="horizontal"
android:padding="0dp"
android:paddingStart="5dp">

<TextView
style="@style/Widget.Android.AppWidget.Text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:layout_marginStart="2dp"
android:layout_marginBottom="0dp"
android:contentDescription="@string/wodwidget_label"
android:paddingBottom="0dp"
android:paddingTop="3dp"
android:text="@string/wodwidget_label"
android:textSize="12sp"
android:textStyle="bold" />
</LinearLayout>

<LinearLayout
style="@style/Widget.Android.AppWidget.InnerView"
android:padding="0dp"
android:layout_width="match_parent"
android:background="@color/background"
android:layout_height="wrap_content"
android:orientation="horizontal">

<TextView
android:id="@+id/wodwidget_word"
style="@style/Widget.Android.AppWidget.Text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:contentDescription="@string/wodwidget_word"
android:fontFamily="@font/ibm_plex_serif_bold"
android:text="@string/wodwidget_word"
android:textSize="32sp"
android:textStyle="bold" />

<TextView
android:id="@+id/wodwidget_nature"
style="@style/Widget.Android.AppWidget.TextSecondary"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAlignment="viewEnd"
android:layout_marginEnd="8dp"
android:contentDescription="@string/wodwidget_nature"
android:fontFamily="@font/ibm_plex_serif_bold"
android:text="@string/wodwidget_nature"
android:textSize="19sp"
android:textStyle="bold" />
</LinearLayout>

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="start|center_vertical"
android:orientation="horizontal">


<TextView
android:id="@+id/wodwidget_phoneme"
style="@style/Widget.Android.AppWidget.TextSecondary"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginStart="8dp"
android:layout_marginBottom="8dp"
android:contentDescription="@string/wodwidget_phoneme"
android:fontFamily="@font/ibm_plex_serif_bold"
android:text="@string/wodwidget_phoneme"
android:textSize="17sp"
android:textStyle="bold" />
</LinearLayout>

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="start|center_vertical"
android:orientation="horizontal">


<TextView
android:id="@+id/wodwidget_definition"
style="@style/Widget.Android.AppWidget.TextTertiary"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginStart="8dp"
android:layout_marginBottom="8dp"
android:contentDescription="@string/wodwidget_desc"
android:fontFamily="@font/ibm_plex_serif_bold"
android:text="@string/wodwidget_desc"
android:textSize="15sp"
android:textStyle="bold" />
</LinearLayout>


</LinearLayout>


</RelativeLayout>
3 changes: 3 additions & 0 deletions app/android/app/src/main/res/values-night-v31/themes.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,8 @@
<style name="AppTheme.AppWidgetContainerParent" parent="@android:style/Theme.DeviceDefault.DayNight">
<item name="appWidgetRadius">@android:dimen/system_app_widget_background_radius</item>
<item name="appWidgetInnerRadius">@android:dimen/system_app_widget_inner_radius</item>
<item name="android:radius">8dp</item>
<item name="appWidgetInnerRadius">8dp</item>
<item name="appWidgetRadius">16dp</item>
</style>
</resources>
10 changes: 10 additions & 0 deletions app/android/app/src/main/res/values-night/colors.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<resources>
<color name="light_blue_50">#FFE1F5FE</color>
<color name="light_blue_200">#FF81D4FA</color>
<color name="light_blue_600">#FF039BE5</color>
<color name="light_blue_900">#FF01579B</color>
<color name="background">#000000</color>
<color name="text">#FFF</color>
<color name="textSecondary">#B9B9B9</color>
<color name="textGrey">#7F7F7F</color>
</resources>
5 changes: 3 additions & 2 deletions app/android/app/src/main/res/values-v31/themes.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
and @android:dimen/system_app_widget_internal_padding requires API level 31
-->
<style name="AppTheme.AppWidgetContainerParent" parent="@android:style/Theme.DeviceDefault.DayNight">
<item name="appWidgetRadius">@android:dimen/system_app_widget_background_radius</item>
<item name="appWidgetInnerRadius">@android:dimen/system_app_widget_inner_radius</item>
<item name="android:radius">8dp</item>
<item name="appWidgetInnerRadius">8dp</item>
<item name="appWidgetRadius">16dp</item>
</style>
</resources>
4 changes: 4 additions & 0 deletions app/android/app/src/main/res/values/colors.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,8 @@
<color name="light_blue_200">#FF81D4FA</color>
<color name="light_blue_600">#FF039BE5</color>
<color name="light_blue_900">#FF01579B</color>
<color name="background">#FFF</color>
<color name="text">#000000</color>
<color name="textSecondary">#565656</color>
<color name="textGrey">#898989</color>
</resources>
Loading

0 comments on commit 435528e

Please sign in to comment.