1111import net .sharksystem .asap .ASAPException ;
1212import net .sharksystem .asap .android .ASAP ;
1313import net .sharksystem .asap .android .ASAPServiceCreationIntent ;
14- import net .sharksystem .asap .android .service . ASAPService ;
14+ import net .sharksystem .asap .android .Util ;
1515
1616import java .util .ArrayList ;
1717import java .util .List ;
2222
2323public class ASAPApplication {
2424 private static final int MY_ASK_FOR_PERMISSIONS_REQUEST = 100 ;
25- private final CharSequence asapOwner ;
26- private final CharSequence rootFolder ;
27- private final boolean onlineExchange ;
25+ private static ASAPApplication singleton ;
26+ private CharSequence asapOwner ;
27+ private CharSequence rootFolder ;
28+ private boolean onlineExchange ;
2829 private boolean initialized = false ;
2930
3031 private boolean btDisoverableOn = false ;
@@ -38,8 +39,12 @@ public class ASAPApplication {
3839 private List <String > deniedPermissions = new ArrayList <>();
3940 private int activityCount = 0 ;
4041
41- protected ASAPApplication (CharSequence asapOwner ) {
42- this (asapOwner , DEFAULT_ROOT_FOLDER_NAME , ASAP .ONLINE_EXCHANGE_DEFAULT );
42+ /**
43+ * setup application by calling getASAPOwner(), getFolderName(), getASAPOnlineExchange().
44+ * Those messagen can and should be overwritten from actual implementations.
45+ */
46+ protected ASAPApplication () {
47+ this (ASAP .UNKNOWN_USER , DEFAULT_ROOT_FOLDER_NAME , ASAP .ONLINE_EXCHANGE_DEFAULT );
4348 }
4449
4550 protected ASAPApplication (CharSequence asapOwner ,
@@ -72,6 +77,11 @@ private void initialize() {
7277// Intent asapServiceCreationIntent = new Intent(activity, ASAPService.class);
7378// asapServiceCreationIntent.putExtra(ASAP.USER, this.asapOwner);
7479
80+ // get owner when initializing
81+ this .asapOwner = this .getASAPOwner (this .getActivity ());
82+ this .rootFolder = this .getASAPRootFolder (this .getActivity ());
83+ this .onlineExchange = this .getASAPOnlineExchange (this .getActivity ());
84+
7585 try {
7686 Intent asapServiceCreationIntent = new ASAPServiceCreationIntent (activity ,
7787 this .asapOwner , this .rootFolder , this .onlineExchange );
@@ -84,10 +94,51 @@ private void initialize() {
8494 }
8595 }
8696
97+ /**
98+ * could be overwritten
99+ * @param activity
100+ * @return
101+ */
102+ protected boolean getASAPOnlineExchange (Activity activity ) {
103+ return this .onlineExchange ;
104+ }
105+
106+ public boolean getASAPOnlineExchange () {
107+ return this .onlineExchange ;
108+ }
109+
110+ /**
111+ * could be overwritten
112+ */
113+ protected CharSequence getASAPRootFolder (Activity activity ) {
114+ return this .rootFolder ;
115+ }
116+
117+ public CharSequence getASAPRootFolder () {
118+ return Util .getASAPRootDirectory (
119+ this .getActivity (), this .rootFolder , this .asapOwner ).getAbsolutePath ();
120+ }
121+
122+ /**
123+ * could be overwritten
124+ */
125+ protected CharSequence getASAPOwner (Activity activity ) {
126+ return this .asapOwner ;
127+ }
128+
129+ public CharSequence getASAPOwner () {
130+ return this .asapOwner ;
131+ }
132+
87133 public static ASAPApplication getASAPApplication () {
88- return new ASAPApplication ("DummyUser" );
134+ if (ASAPApplication .singleton == null ) {
135+ ASAPApplication .singleton = new ASAPApplication ();
136+ }
137+
138+ return ASAPApplication .singleton ;
89139 }
90140
141+
91142 public void activityCreated (ASAPActivity asapActivity ) {
92143 this .setActivity (asapActivity );
93144 this .initialize ();
0 commit comments