Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
mytfg
mytfg-vplan-app
Commits
ae4d4ed4
Commit
ae4d4ed4
authored
Jan 23, 2017
by
Lennart Bader
Browse files
Made Login Optional
parent
aefc7723
Changes
9
Hide whitespace changes
Inline
Side-by-side
app/src/main/java/de/mytfg/apps/vplan/activities/MainActivity.java
View file @
ae4d4ed4
...
...
@@ -60,11 +60,6 @@ public class MainActivity extends AppCompatActivity {
@Override
public
boolean
onNavigationItemSelected
(
@NonNull
MenuItem
item
)
{
MyTFGApi
api
=
new
MyTFGApi
(
context
);
if
(!
api
.
isLoggedIn
())
{
navi
.
clear
();
navi
.
navigate
(
new
LoginFragment
(),
R
.
id
.
fragment_container
);
return
true
;
}
switch
(
item
.
getItemId
())
{
default
:
return
false
;
...
...
@@ -73,8 +68,13 @@ public class MainActivity extends AppCompatActivity {
navi
.
navigate
(
new
StartFragment
(),
R
.
id
.
fragment_container
);
return
true
;
case
R
.
id
.
mainmenu_plan
:
// Login required to see VPlan
navi
.
clear
();
navi
.
navigate
(
new
PlanFragment
(),
R
.
id
.
fragment_container
);
if
(!
api
.
isLoggedIn
())
{
navi
.
navigate
(
new
LoginFragment
(),
R
.
id
.
fragment_container
);
}
else
{
navi
.
navigate
(
new
PlanFragment
(),
R
.
id
.
fragment_container
);
}
return
true
;
case
R
.
id
.
mainmenu_vrr
:
navi
.
clear
();
...
...
@@ -108,9 +108,11 @@ public class MainActivity extends AppCompatActivity {
Fragment
fragment
;
Settings
settings
=
new
Settings
(
context
);
MyTFGApi
api
=
new
MyTFGApi
(
context
);
if
(!
api
.
isLoggedIn
())
{
if
(!
api
.
isLoggedIn
()
&&
!
settings
.
getBool
(
"first_login_hint"
))
{
settings
.
save
(
"first_login_hint"
,
true
);
fragment
=
new
LoginFragment
();
}
else
{
if
(
savedInstanceState
!=
null
)
{
...
...
@@ -118,13 +120,7 @@ public class MainActivity extends AppCompatActivity {
"fragmentInstanceSaved"
);
}
else
{
// Read Landing Page from settings
Settings
settings
=
new
Settings
(
context
);
int
page
=
settings
.
getInt
(
"landing_page"
);
String
[]
fragmentNames
=
getResources
().
getStringArray
(
R
.
array
.
settings_opt_landing_page_fragments
);
String
fragName
=
"StartFragment"
;
if
(
page
>=
0
&&
page
<
fragmentNames
.
length
)
{
fragName
=
fragmentNames
[
page
];
}
String
fragName
=
settings
.
getString
(
"landing_page"
);
try
{
fragName
=
"de.mytfg.apps.vplan.fragments."
+
fragName
;
Class
c
=
Class
.
forName
(
fragName
);
...
...
app/src/main/java/de/mytfg/apps/vplan/fragments/LoginFragment.java
View file @
ae4d4ed4
...
...
@@ -8,6 +8,8 @@ import android.support.annotation.Nullable;
import
android.support.design.widget.CoordinatorLayout
;
import
android.support.design.widget.Snackbar
;
import
android.support.v4.app.Fragment
;
import
android.support.v4.widget.TextViewCompat
;
import
android.text.Html
;
import
android.util.Log
;
import
android.view.LayoutInflater
;
import
android.view.Menu
;
...
...
@@ -16,6 +18,7 @@ import android.view.View;
import
android.view.ViewGroup
;
import
android.widget.Button
;
import
android.widget.EditText
;
import
android.widget.TextView
;
import
org.json.JSONException
;
import
org.json.JSONObject
;
...
...
@@ -51,6 +54,9 @@ public class LoginFragment extends Fragment {
EditText
username
=
(
EditText
)
view
.
findViewById
(
R
.
id
.
login_username
);
username
.
setText
(
api
.
getUsername
());
TextView
loginText
=
(
TextView
)
view
.
findViewById
(
R
.
id
.
login_text
);
loginText
.
setText
(
Html
.
fromHtml
(
getString
(
R
.
string
.
login_text
)));
// Set Login Button listener
Button
loginButton
=
(
Button
)
view
.
findViewById
(
R
.
id
.
login_button
);
loginButton
.
setOnClickListener
(
new
View
.
OnClickListener
()
{
...
...
app/src/main/java/de/mytfg/apps/vplan/fragments/PlanFragment.java
View file @
ae4d4ed4
...
...
@@ -28,6 +28,7 @@ import de.mytfg.apps.vplan.R;
import
de.mytfg.apps.vplan.activities.MainActivity
;
import
de.mytfg.apps.vplan.adapters.FragmentHolder
;
import
de.mytfg.apps.vplan.adapters.ViewPagerAdapter
;
import
de.mytfg.apps.vplan.api.MyTFGApi
;
import
de.mytfg.apps.vplan.logic.PlanLogic
;
import
de.mytfg.apps.vplan.objects.Vplan
;
import
de.mytfg.apps.vplan.toolbar.ToolbarManager
;
...
...
@@ -52,6 +53,7 @@ public class PlanFragment extends Fragment {
public
View
onCreateView
(
LayoutInflater
inflater
,
@Nullable
ViewGroup
container
,
@Nullable
Bundle
savedInstanceState
)
{
view
=
inflater
.
inflate
(
R
.
layout
.
fragment_plan
,
container
,
false
);
final
MainActivity
context
=
(
MainActivity
)
this
.
getActivity
();
this
.
context
=
context
;
context
.
getToolbarManager
()
.
clear
(
false
)
...
...
@@ -62,14 +64,6 @@ public class PlanFragment extends Fragment {
.
showFab
()
.
setTabOutscroll
(
true
);
// Create logics
/*todayPlan = new Vplan(context, "today");
tomorrowPlan = new Vplan(context, "tomorrow");
today = new PlanLogic(todayPlan);
tomorrow = new PlanLogic(tomorrowPlan);
*/
setHasOptionsMenu
(
true
);
FloatingActionButton
fab
=
(
FloatingActionButton
)
context
.
findViewById
(
R
.
id
.
fab
);
...
...
app/src/main/java/de/mytfg/apps/vplan/fragments/SettingsFragment.java
View file @
ae4d4ed4
...
...
@@ -10,6 +10,7 @@ import android.support.design.widget.CoordinatorLayout;
import
android.support.design.widget.Snackbar
;
import
android.support.v4.app.Fragment
;
import
android.support.v7.app.AlertDialog
;
import
android.support.v7.widget.CardView
;
import
android.text.Html
;
import
android.text.TextUtils
;
import
android.util.Log
;
...
...
@@ -62,50 +63,72 @@ public class SettingsFragment extends Fragment {
.
setTitle
(
getString
(
R
.
string
.
menutitle_settings
))
.
setExpandable
(
true
,
true
);
MyTFGApi
api
=
new
MyTFGApi
(
context
);
String
device
=
api
.
getStoredDevice
();
long
expirets
=
api
.
getExpire
();
String
expire
=
api
.
getExpireString
();
final
User
user
=
api
.
getUser
();
updateViews
();
TextView
username
=
(
TextView
)
view
.
findViewById
(
R
.
id
.
account_name
);
username
.
setText
(
user
.
getUsername
());
TextView
text
=
(
TextView
)
view
.
findViewById
(
R
.
id
.
account_info_text
);
text
.
setText
(
Html
.
fromHtml
(
String
.
format
(
getString
(
R
.
string
.
account_info_text
),
user
.
getFirstname
(),
user
.
getLastname
(),
user
.
getUsername
(),
device
,
expire
,
user
.
getLevel
(),
user
.
getGrade
()
)
));
return
view
;
}
Button
logoutbtn
=
(
Button
)
view
.
findViewById
(
R
.
id
.
logout_button
);
logoutbtn
.
setOnClickListener
(
new
View
.
OnClickListener
()
{
@Override
public
void
onClick
(
View
view
)
{
MyTFGApi
api
=
new
MyTFGApi
(
context
);
api
.
logout
(
false
);
private
void
updateViews
()
{
CardView
details
=
(
CardView
)
view
.
findViewById
(
R
.
id
.
account_loggedin
);
CardView
login
=
(
CardView
)
view
.
findViewById
(
R
.
id
.
account_goto_login
);
CardView
additional
=
(
CardView
)
view
.
findViewById
(
R
.
id
.
account_additional_card
);
CoordinatorLayout
coordinatorLayout
=
(
CoordinatorLayout
)
context
.
findViewById
(
R
.
id
.
coordinator_layout
);
Snackbar
snackbar
=
Snackbar
.
make
(
coordinatorLayout
,
getString
(
R
.
string
.
account_logged_out
),
Snackbar
.
LENGTH_LONG
);
snackbar
.
show
();
context
.
getNavi
().
clear
();
context
.
getNavi
().
navigate
(
new
LoginFragment
(),
R
.
id
.
fragment_container
);
}
});
MyTFGApi
api
=
new
MyTFGApi
(
context
);
if
(
api
.
isLoggedIn
())
{
login
.
setVisibility
(
View
.
GONE
);
details
.
setVisibility
(
View
.
VISIBLE
);
additional
.
setVisibility
(
View
.
VISIBLE
);
String
device
=
api
.
getStoredDevice
();
long
expirets
=
api
.
getExpire
();
String
expire
=
api
.
getExpireString
();
final
User
user
=
api
.
getUser
();
updateSettings
();
TextView
username
=
(
TextView
)
view
.
findViewById
(
R
.
id
.
account_name
);
username
.
setText
(
user
.
getUsername
());
TextView
text
=
(
TextView
)
view
.
findViewById
(
R
.
id
.
account_info_text
);
text
.
setText
(
Html
.
fromHtml
(
String
.
format
(
getString
(
R
.
string
.
account_info_text
),
user
.
getFirstname
(),
user
.
getLastname
(),
user
.
getUsername
(),
device
,
expire
,
user
.
getLevel
(),
user
.
getGrade
()
)
));
updateAdditionalClasses
();
Button
logoutbtn
=
(
Button
)
view
.
findViewById
(
R
.
id
.
logout_button
);
logoutbtn
.
setOnClickListener
(
new
View
.
OnClickListener
()
{
@Override
public
void
onClick
(
View
view
)
{
MyTFGApi
api
=
new
MyTFGApi
(
context
);
api
.
logout
(
false
);
return
view
;
CoordinatorLayout
coordinatorLayout
=
(
CoordinatorLayout
)
context
.
findViewById
(
R
.
id
.
coordinator_layout
);
Snackbar
snackbar
=
Snackbar
.
make
(
coordinatorLayout
,
getString
(
R
.
string
.
account_logged_out
),
Snackbar
.
LENGTH_LONG
);
snackbar
.
show
();
updateViews
();
}
});
updateAdditionalClasses
();
}
else
{
login
.
setVisibility
(
View
.
VISIBLE
);
details
.
setVisibility
(
View
.
GONE
);
additional
.
setVisibility
(
View
.
GONE
);
login
.
setOnClickListener
(
new
View
.
OnClickListener
()
{
@Override
public
void
onClick
(
View
view
)
{
((
MainActivity
)
getActivity
()).
getNavi
().
navigate
(
new
LoginFragment
(),
R
.
id
.
fragment_container
);
}
});
}
updateSettings
();
}
@Override
...
...
@@ -224,7 +247,7 @@ public class SettingsFragment extends Fragment {
break
;
default
:
explanation
.
setText
(
Html
.
fromHtml
(
String
.
format
(
getString
(
R
.
string
.
account_additional_explanation_
pupi
l
),
String
.
format
(
getString
(
R
.
string
.
account_additional_explanation_
highleve
l
),
user
.
getLevel
())
));
break
;
...
...
@@ -298,11 +321,21 @@ public class SettingsFragment extends Fragment {
}
});
landing
.
setSelection
(
settings
.
getInt
(
"landing_page"
));
String
selection
=
settings
.
getString
(
"landing_page"
);
int
selectedId
=
0
;
String
[]
arr
=
getResources
().
getStringArray
(
R
.
array
.
settings_opt_landing_page_fragments
);
for
(
int
i
=
0
;
i
<
arr
.
length
;
++
i
)
{
if
(
arr
[
i
].
equals
(
selection
))
{
selectedId
=
i
;
break
;
}
}
landing
.
setSelection
(
selectedId
);
landing
.
setOnItemSelectedListener
(
new
AdapterView
.
OnItemSelectedListener
()
{
@Override
public
void
onItemSelected
(
AdapterView
<?>
adapterView
,
View
view
,
int
i
,
long
l
)
{
settings
.
save
(
"landing_page"
,
i
);
settings
.
save
(
"landing_page"
,
getResources
().
getStringArray
(
R
.
array
.
settings_opt_landing_page_fragments
)[
i
]
);
}
@Override
...
...
app/src/main/java/de/mytfg/apps/vplan/tools/Settings.java
View file @
ae4d4ed4
...
...
@@ -47,6 +47,12 @@ public class Settings {
return
preferences
.
getString
(
option
,
""
);
}
public
void
clear
(
String
option
)
{
preferences
.
edit
()
.
remove
(
option
)
.
apply
();
}
public
int
getInt
(
String
option
)
{
return
preferences
.
getInt
(
option
,
0
);
}
...
...
app/src/main/res/layout/fragment_login.xml
View file @
ae4d4ed4
...
...
@@ -32,11 +32,12 @@
android:textSize=
"@dimen/textTitle"
android:layout_width=
"match_parent"
android:layout_height=
"wrap_content"
android:text=
"@string/
app_nam
e"
/>
android:text=
"@string/
login_titl
e"
/>
<TextView
android:textSize=
"@dimen/textDefault"
android:layout_width=
"match_parent"
android:layout_height=
"wrap_content"
android:id=
"@+id/login_text"
android:text=
"@string/login_text"
/>
</LinearLayout>
...
...
app/src/main/res/layout/fragment_settings.xml
View file @
ae4d4ed4
...
...
@@ -12,10 +12,56 @@
android:fitsSystemWindows=
"true"
xmlns:android=
"http://schemas.android.com/apk/res/android"
>
<android.support.v7.widget.CardView
android:layout_width=
"match_parent"
android:layout_height=
"wrap_content"
android:padding=
"@dimen/cardview_spacing"
android:visibility=
"gone"
android:id=
"@+id/account_goto_login"
android:layout_marginBottom=
"@dimen/defaultPadding"
>
<LinearLayout
android:layout_width=
"match_parent"
android:layout_height=
"match_parent"
android:orientation=
"horizontal"
android:padding=
"@dimen/cardview_spacing"
android:background=
"@color/colorPrimaryLight"
>
<ImageView
android:layout_width=
"60dp"
android:layout_gravity=
"start"
android:layout_height=
"60dp"
android:layout_marginEnd=
"20dp"
android:scaleType=
"fitEnd"
android:src=
"@mipmap/ic_mytfg_launcher_raw"
android:layout_marginRight=
"@dimen/cardview_default_radius"
/>
<TextView
android:textSize=
"@dimen/textTitle"
android:layout_width=
"0dp"
android:layout_height=
"wrap_content"
android:layout_weight=
"1"
android:layout_gravity=
"center_vertical"
android:text=
"@string/login_action"
/>
<ImageView
android:layout_width=
"wrap_content"
android:layout_gravity=
"center_vertical|end"
android:layout_height=
"wrap_content"
android:layout_marginStart=
"10dp"
android:scaleType=
"centerInside"
android:src=
"@drawable/ic_action_open_link"
android:layout_marginLeft=
"10dp"
/>
</LinearLayout>
</android.support.v7.widget.CardView>
<android.support.v7.widget.CardView
android:layout_width=
"match_parent"
android:layout_height=
"wrap_content"
android:padding=
"@dimen/cardview_spacing"
android:id=
"@+id/account_loggedin"
android:layout_marginBottom=
"@dimen/defaultPadding"
>
<LinearLayout
...
...
@@ -53,6 +99,7 @@
<android.support.v7.widget.CardView
android:layout_width=
"match_parent"
android:layout_height=
"wrap_content"
android:id=
"@+id/account_additional_card"
android:padding=
"@dimen/cardview_spacing"
android:layout_marginBottom=
"@dimen/defaultPadding"
>
...
...
app/src/main/res/values-de/strings.xml
View file @
ae4d4ed4
...
...
@@ -33,8 +33,12 @@
<string
name=
"api_vrr_error"
>
Abfahrtszeiten konnten nicht geladen werden
</string>
<!-- LOGIN -->
<string
name=
"login_text"
>
Um diese App und all ihre Funktionen nutzen zu können,
müssen Sie sich anmelden.
</string>
<string
name=
"login_text"
>
Für den Zugriff auf den Vertretungsplan ist eine Anmeldung erforderlich.
<
br />
Sie können sich mit Ihrem MyTFG Account anmelden.
<
br />
Eltern können den Zugang des Kindes nutzen.
<
br />
Klassen von Geschwistern oder Freunden können anschließend in den Einstellungen ausgewählt werden.
</string>
<string
name=
"login_action"
>
Anmelden
</string>
<string
name=
"login_hint_username"
>
Nutzername
</string>
<string
name=
"login_hint_password"
>
Passwort
</string>
...
...
@@ -102,7 +106,7 @@
Sie haben die Möglichkeit, verschiedene Klassen hinzuzufügen, für die Sie ebenfalls Einträge erhalten wollen.
</string>
<string
name=
"account_additional_explanation_highlevel"
>
Als %1$s erhalten Sie alle Einträge de
r
Vertretungsplans.
<
br/>
Als %1$s erhalten Sie alle Einträge de
s
Vertretungsplans.
<
br/>
Somit können Sie keine zusätzlichen Klassen wählen.
</string>
<string
name=
"account_addional_classes"
>
<
b>Zusätzliche Klassen
<
/b>
<
br/>%1$s
</string>
...
...
app/src/main/res/values/strings.xml
View file @
ae4d4ed4
...
...
@@ -68,6 +68,7 @@
<string
name=
"api_vrr_error"
>
VRR Data could not be loaded
</string>
<!-- LOGIN -->
<string
name=
"login_title"
>
MyTFG Login
</string>
<string
name=
"login_text"
>
To use this App and all its features you have to login first.
</string>
<string
name=
"login_action"
>
Login
</string>
<string
name=
"login_hint_username"
>
Username
</string>
...
...
@@ -119,11 +120,13 @@
<string-array
name=
"settings_opt_landing_page_entries"
>
<item>
@string/menutitle_home
</item>
<item>
@string/menutitle_plan
</item>
<item>
@string/menutitle_vrr
</item>
<item>
@string/menutitle_about
</item>
</string-array>
<string-array
name=
"settings_opt_landing_page_fragments"
>
<item>
StartFragment
</item>
<item>
PlanFragment
</item>
<item>
VrrFragment
</item>
<item>
AboutFragment
</item>
</string-array>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment