Skip to content
This repository was archived by the owner on Jun 22, 2023. It is now read-only.

Commit 8e7649d

Browse files
authored
PR #97 - Added Share functionality
Added Share-Functionality
2 parents 4180c83 + cfde1c0 commit 8e7649d

File tree

11 files changed

+140
-15
lines changed

11 files changed

+140
-15
lines changed

.travis.yml

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ env:
77
- ANDROID_API=28
88
- EMULATOR_API=28
99
- ANDROID_BUILD_TOOLS=28.0.3
10-
10+
- LC_ALL='de_DE.UTF-8'
11+
1112
android:
1213
components:
1314
- tools
@@ -21,6 +22,11 @@ android:
2122
- 'intel-android-extra-license-.+'
2223
- '.*'
2324

25+
addons:
26+
apt:
27+
packages:
28+
- language-pack-de
29+
2430
notifications:
2531
email: false
2632

@@ -34,11 +40,11 @@ cache:
3440
- $HOME/.android/build-cache
3541

3642
before_install:
37-
- openssl aes-256-cbc -K $encrypted_6ab911f61ce6_key -iv $encrypted_6ab911f61ce6_iv -in keystore.ks.enc -out keystore.ks -d
43+
- 'if [ -n "$TRAVIS_TAG" ]; then openssl aes-256-cbc -K $encrypted_6ab911f61ce6_key -iv $encrypted_6ab911f61ce6_iv -in keystore.ks.enc -out keystore.ks -d; else echo "Not building a tagged commit! Skipping decrypting!"; fi'
3844

3945
script:
4046
- ./gradlew jacocoTestReport coveralls
41-
- ./gradlew clean build
47+
- 'if [ -n "$TRAVIS_TAG" ]; then ./gradlew clean assembleRelease; else echo "Not building a tagged commit! Skipping building release apk!"; fi'
4248

4349
deploy:
4450
provider: releases

app/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ android {
2525
applicationId "de.aurora.mggvertretungsplan"
2626
minSdkVersion 15
2727
targetSdkVersion 28
28-
versionCode 28
29-
versionName "3.2.1"
28+
versionCode 30
29+
versionName "3.2.2"
3030
multiDexEnabled true
3131

3232
testInstrumentationRunner 'android.support.test.runner.AndroidJUnitRunner'

app/src/main/java/de/aurora/mggvertretungsplan/MainActivity.java

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,6 @@
2121
import android.view.MenuItem;
2222
import android.widget.Toast;
2323

24-
import org.json.JSONArray;
25-
import org.json.JSONException;
26-
2724
import androidx.annotation.ColorInt;
2825
import androidx.appcompat.app.AlertDialog;
2926
import androidx.appcompat.app.AppCompatActivity;
@@ -34,7 +31,12 @@
3431
import androidx.recyclerview.widget.LinearLayoutManager;
3532
import androidx.recyclerview.widget.RecyclerView;
3633
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
34+
35+
import org.json.JSONArray;
36+
import org.json.JSONException;
37+
3738
import de.aurora.mggvertretungsplan.datamodel.TimeTable;
39+
import de.aurora.mggvertretungsplan.datamodel.TimeTableDay;
3840
import de.aurora.mggvertretungsplan.parsing.BaseParser;
3941
import de.aurora.mggvertretungsplan.parsing.BaseParser.ParsingCompleteListener;
4042
import de.aurora.mggvertretungsplan.parsing.MGGParser;
@@ -220,6 +222,39 @@ public boolean onOptionsItemSelected(MenuItem item) {
220222
case R.id.action_feedback:
221223
launchCustomTabsIntent(color, getString(R.string.feedback_url));
222224
break;
225+
case R.id.action_share:
226+
StringBuilder sb = new StringBuilder();
227+
String header = getString(R.string.toolbarTitle_WithClass, class_name);
228+
sb.append(header);
229+
sb.append("\n");
230+
231+
String input = StorageUtilities.readFile(this);
232+
TimeTable timeTable;
233+
234+
if (input.isEmpty()) {
235+
timeTable = new TimeTable();
236+
} else {
237+
try {
238+
JSONArray jsonArray = new JSONArray(input);
239+
timeTable = new TimeTable(jsonArray);
240+
timeTable = timeTable.filter(class_name);
241+
} catch (JSONException e) {
242+
Logger.e(TAG, e.getMessage());
243+
timeTable = new TimeTable();
244+
}
245+
}
246+
247+
for (TimeTableDay ttd : timeTable.getAllDays()) {
248+
sb.append(ttd.toShareString());
249+
}
250+
251+
Intent shareIntent = new Intent(Intent.ACTION_SEND);
252+
shareIntent.setType("text/plain");
253+
shareIntent.putExtra(Intent.EXTRA_SUBJECT, "Vertretungsplan des Markgrafen-Gymnasiums");
254+
shareIntent.putExtra(Intent.EXTRA_TEXT, sb.toString().trim());
255+
startActivity(Intent.createChooser(shareIntent, "Teilen via..."));
256+
break;
257+
223258
case R.id.action_info:
224259
Spanned informationText;
225260
if (Build.VERSION.SDK_INT >= 24) {

app/src/main/java/de/aurora/mggvertretungsplan/datamodel/TimeTable.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,21 @@ public String toString() {
135135
return result.toString().trim();
136136
}
137137

138+
/**
139+
* Filters the timetable so that only entries of a certain class will stay. All other classes
140+
* will be removed.
141+
* @param class_name The name of the class, which should be filtered on.
142+
* @return TimeTable object
143+
*/
144+
public TimeTable filter(String className) {
145+
final TimeTable tt = new TimeTable();
146+
for (TimeTableDay ttd: timeTableDays) {
147+
tt.addDay(ttd.filter(className));
148+
}
149+
150+
return tt;
151+
}
152+
138153
public JSONArray toJSON() throws JSONException {
139154
JSONArray jsonArray = new JSONArray();
140155

app/src/main/java/de/aurora/mggvertretungsplan/datamodel/TimeTableDay.java

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,14 @@ public TimeTableDay(String date, String week, ArrayList<ArrayList<String>> timeT
3636
mergeConsecutiveCancellations();
3737
}
3838

39+
public TimeTableDay(Date date, Week week, ArrayList<TimeTableElement> timeTableElements) {
40+
this.date = date;
41+
this.week = week;
42+
for (TimeTableElement tte: timeTableElements) {
43+
addElement(tte);
44+
}
45+
}
46+
3947
public TimeTableDay(JSONObject jsonObject) {
4048
try {
4149
String date = jsonObject.getString("date");
@@ -125,6 +133,10 @@ public ArrayList<TimeTableElement> getElements(String className) {
125133
return elementsOfClass;
126134
}
127135

136+
public TimeTableDay filter(String className) {
137+
return new TimeTableDay(this.date, this.week, getElements(className));
138+
}
139+
128140
public ArrayList<ArrayList<String>> getArrayList() {
129141
ArrayList<ArrayList<String>> elements = new ArrayList<>();
130142

@@ -253,6 +265,33 @@ public String toString() {
253265
return result.toString().trim();
254266
}
255267

268+
/**
269+
* Formats the TTD in a beautiful way to share the TT via other apps
270+
* @return Beautiful formatted string of the TTD's content
271+
*/
272+
public String toShareString() {
273+
StringBuilder result = new StringBuilder();
274+
result.append(getFullDateString());
275+
result.append(", ");
276+
result.append(this.week.toString());
277+
result.append("-Woche\n");
278+
279+
if (timeTableElements.isEmpty()) {
280+
//result.append(getString(R.string.card_no_information));
281+
//TODO Remove hardcoded string
282+
result.append("Keine Ausfälle!");
283+
result.append("\n\n");
284+
return result.toString();
285+
}
286+
287+
for (TimeTableElement tte : timeTableElements) {
288+
result.append(tte.toShareString());
289+
}
290+
result.append("\n");
291+
292+
return result.toString();
293+
}
294+
256295
public JSONObject toJSON() throws JSONException {
257296
JSONObject jsonObject = new JSONObject();
258297
jsonObject.put("date", getDateString());

app/src/main/java/de/aurora/mggvertretungsplan/datamodel/TimeTableElement.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,25 @@ public String toString() {
256256
return String.format("%s | %s | %s | %s | %s | %s | %s", hour, class_name, subject, newSubject, room, newRoom, info);
257257
}
258258

259+
/**
260+
* Formats the TTD in a beautiful way to share the TT via other apps
261+
* @return Beautiful formatted string of the TTD's content
262+
*/
263+
public String toShareString() {
264+
// TODO There should be some way to see what subject is cancelled / substituted,
265+
// especially important for K1 / K2 because there are multiple subjects taking place
266+
// at the same time
267+
int type = getType();
268+
if (type == CANCELLATION) {
269+
return String.format(" > %s. Stunde entfällt! %s\n", hour, info);
270+
}
271+
if (type == SUBSTITUTION) {
272+
return String.format(" > %s. Stunde: %s -> %s\n", hour, room, newRoom);
273+
}
274+
return "FEHLER!\n";
275+
//TODO remove hardcoded strings!
276+
}
277+
259278
public JSONObject toJSON() throws JSONException {
260279
JSONObject jsonObject = new JSONObject();
261280

app/src/main/res/menu/toolbar_menu.xml

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,31 @@
22
xmlns:app="http://schemas.android.com/apk/res-auto">
33

44
<item
5-
android:id="@+id/action_info"
5+
android:id="@+id/action_share"
6+
android:icon="@android:drawable/ic_menu_share"
67
android:orderInCategory="1"
8+
android:title="@string/action_share_title" />
9+
<item
10+
android:id="@+id/action_info"
11+
android:orderInCategory="2"
712
android:title="@string/infoTitle"
813
app:showAsAction="never" />
914

1015
<item
1116
android:id="@+id/action_settings"
12-
android:orderInCategory="2"
17+
android:orderInCategory="3"
1318
android:title="@string/action_settings"
1419
app:showAsAction="never" />
1520

1621
<item
1722
android:id="@+id/action_feedback"
18-
android:orderInCategory="3"
23+
android:orderInCategory="4"
1924
android:title="@string/action_feedback"
2025
app:showAsAction="never" />
2126

2227
<item
2328
android:id="@+id/action_website"
24-
android:orderInCategory="4"
29+
android:orderInCategory="5"
2530
android:title="@string/action_website"
2631
app:showAsAction="never" />
2732

app/src/main/res/values/strings.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@
7676
<string name="defaultChannelDesc">Benachrichtigungen über Änderungen des Vertretungsplans</string>
7777
<string name="newsChannelDisplayName">Neuigkeiten</string>
7878
<string name="newsChannelDesc">Nachrichten der MGG Webseite</string>
79+
<string name="action_share_title">Teilen...</string>
7980

8081
<string-array name="ClassLayer_List">
8182
<item>5</item>

app/src/test/java/de/aurora/mggvertretungsplan/datamodel/TimeTableElementTest.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,4 +96,9 @@ public void testToString() {
9696
assertEquals(String.format("%s | %s | %s | %s | %s | %s | %s", hour, class_name, "Deutsch", "Englisch", room, newRoom, info), tte.toString());
9797
}
9898

99+
@Test
100+
public void testToShareString() {
101+
TimeTableElement tte = new TimeTableElement(hour, class_name, subject, newSubject, room, newRoom, info);
102+
assertEquals(String.format(" > %s. Stunde: %s -> %s\n", hour, room, newRoom), tte.toShareString());
103+
}
99104
}

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ buildscript {
88
google()
99
}
1010
dependencies {
11-
classpath 'com.android.tools.build:gradle:3.2.1'
11+
classpath 'com.android.tools.build:gradle:3.4.1'
1212
classpath 'org.jacoco:org.jacoco.core:0.8.2'
1313
classpath 'org.kt3k.gradle.plugin:coveralls-gradle-plugin:2.8.2'
1414
}

0 commit comments

Comments
 (0)