Skip to content

Commit

Permalink
Merge pull request #35 from SaltechSystems/example-updates
Browse files Browse the repository at this point in the history
Couchbase Lite Version / example logging out and updated logging
  • Loading branch information
bawelter committed Apr 21, 2020
2 parents fb0c7ac + a548940 commit 9bb4af7
Show file tree
Hide file tree
Showing 17 changed files with 133 additions and 97 deletions.
9 changes: 8 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,11 @@

## 2.7.0+3

* Giving a simplified example and advanced example
* Giving a simplified example and advanced example

## 2.7.1

* Update libraries to version 2.7.1
* Fixed example for logging out
* Updated console logging to Debug for debug mode / Error for everything else
* Removed file logging
2 changes: 1 addition & 1 deletion android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,6 @@ android {
disable 'InvalidPackage'
}
dependencies {
implementation 'com.couchbase.lite:couchbase-lite-android:2.7.0'
implementation 'com.couchbase.lite:couchbase-lite-android:2.7.1'
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,11 @@ class CBManager {
private DatabaseConfiguration mDBConfig;
private CBManagerDelegate mDelegate;

CBManager(CBManagerDelegate delegate, boolean enableLogging) {
CBManager(CBManagerDelegate delegate, LogLevel logLevel) {
mDelegate = delegate;
mDBConfig = new DatabaseConfiguration();

if (enableLogging) {
final File path = mDelegate.getContext().getCacheDir();
Database.log.getFile().setConfig(new LogFileConfiguration(path.toString()));
Database.log.getFile().setLevel(LogLevel.INFO);
}
Database.log.getConsole().setLevel(logLevel);
}

Database getDatabase(String name) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import com.couchbase.lite.DocumentReplication;
import com.couchbase.lite.DocumentReplicationListener;
import com.couchbase.lite.ListenerToken;
import com.couchbase.lite.LogLevel;
import com.couchbase.lite.Query;
import com.couchbase.lite.QueryChange;
import com.couchbase.lite.QueryChangeListener;
Expand Down Expand Up @@ -85,9 +86,9 @@ public CouchbaseLitePlugin(Registrar registrar) {
CouchbaseLite.init(this.getContext());

if (BuildConfig.DEBUG) {
mCBManager = new CBManager(this,true);
mCBManager = new CBManager(this, LogLevel.DEBUG);
} else {
mCBManager = new CBManager(this,false);
mCBManager = new CBManager(this, LogLevel.ERROR);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,5 @@ private void setWhere() {
String _whereClause = _internalMap.get("where");
Expression _expression = QueryManager.getExpressionFromString(_whereClause);
}


}
}
87 changes: 53 additions & 34 deletions example/ios/Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -15,53 +15,72 @@ def parse_KV_file(file, separator='=')
if !File.exists? file_abs_path
return [];
end
pods_ary = []
generated_key_values = {}
skip_line_start_symbols = ["#", "/"]
File.foreach(file_abs_path) { |line|
next if skip_line_start_symbols.any? { |symbol| line =~ /^\s*#{symbol}/ }
plugin = line.split(pattern=separator)
if plugin.length == 2
podname = plugin[0].strip()
path = plugin[1].strip()
podpath = File.expand_path("#{path}", file_abs_path)
pods_ary.push({:name => podname, :path => podpath});
else
puts "Invalid plugin specification: #{line}"
end
}
return pods_ary
File.foreach(file_abs_path) do |line|
next if skip_line_start_symbols.any? { |symbol| line =~ /^\s*#{symbol}/ }
plugin = line.split(pattern=separator)
if plugin.length == 2
podname = plugin[0].strip()
path = plugin[1].strip()
podpath = File.expand_path("#{path}", file_abs_path)
generated_key_values[podname] = podpath
else
puts "Invalid plugin specification: #{line}"
end
end
generated_key_values
end

target 'Runner' do
use_frameworks!
use_modular_headers!

# Flutter Pod

# Prepare symlinks folder. We use symlinks to avoid having Podfile.lock
# referring to absolute paths on developers' machines.
system('rm -rf .symlinks')
system('mkdir -p .symlinks/plugins')
copied_flutter_dir = File.join(__dir__, 'Flutter')
copied_framework_path = File.join(copied_flutter_dir, 'Flutter.framework')
copied_podspec_path = File.join(copied_flutter_dir, 'Flutter.podspec')
unless File.exist?(copied_framework_path) && File.exist?(copied_podspec_path)
# Copy Flutter.framework and Flutter.podspec to Flutter/ to have something to link against if the xcode backend script has not run yet.
# That script will copy the correct debug/profile/release version of the framework based on the currently selected Xcode configuration.
# CocoaPods will not embed the framework on pod install (before any build phases can generate) if the dylib does not exist.

# Flutter Pods
generated_xcode_build_settings = parse_KV_file('./Flutter/Generated.xcconfig')
if generated_xcode_build_settings.empty?
puts "Generated.xcconfig must exist. If you're running pod install manually, make sure flutter packages get is executed first."
end
generated_xcode_build_settings.map { |p|
if p[:name] == 'FLUTTER_FRAMEWORK_DIR'
symlink = File.join('.symlinks', 'flutter')
File.symlink(File.dirname(p[:path]), symlink)
pod 'Flutter', :path => File.join(symlink, File.basename(p[:path]))
generated_xcode_build_settings_path = File.join(copied_flutter_dir, 'Generated.xcconfig')
unless File.exist?(generated_xcode_build_settings_path)
raise "Generated.xcconfig must exist. If you're running pod install manually, make sure flutter pub get is executed first"
end
}
generated_xcode_build_settings = parse_KV_file(generated_xcode_build_settings_path)
cached_framework_dir = generated_xcode_build_settings['FLUTTER_FRAMEWORK_DIR'];

unless File.exist?(copied_framework_path)
FileUtils.cp_r(File.join(cached_framework_dir, 'Flutter.framework'), copied_flutter_dir)
end
unless File.exist?(copied_podspec_path)
FileUtils.cp(File.join(cached_framework_dir, 'Flutter.podspec'), copied_flutter_dir)
end
end

# Keep pod path relative so it can be checked into Podfile.lock.
pod 'Flutter', :path => 'Flutter'

# Plugin Pods

# Prepare symlinks folder. We use symlinks to avoid having Podfile.lock
# referring to absolute paths on developers' machines.
system('rm -rf .symlinks')
system('mkdir -p .symlinks/plugins')
plugin_pods = parse_KV_file('../.flutter-plugins')
plugin_pods.map { |p|
symlink = File.join('.symlinks', 'plugins', p[:name])
File.symlink(p[:path], symlink)
pod p[:name], :path => File.join(symlink, 'ios')
}
plugin_pods.each do |name, path|
symlink = File.join('.symlinks', 'plugins', name)
File.symlink(path, symlink)
pod name, :path => File.join(symlink, 'ios')
end
end

# Prevent Cocoapods from embedding a second Flutter framework and causing an error with the new Xcode build system.
install! 'cocoapods', :disable_input_output_paths => true

post_install do |installer|
installer.pods_project.targets.each do |target|
target.build_configurations.each do |config|
Expand Down
44 changes: 34 additions & 10 deletions example/ios/Podfile.lock
Original file line number Diff line number Diff line change
@@ -1,29 +1,53 @@
PODS:
- couchbase_lite (0.0.1):
- CouchbaseLite-Swift (~> 2.5.1)
- CouchbaseLite-Swift (~> 2.7.0)
- Flutter
- CouchbaseLite-Swift (2.5.1)
- CouchbaseLite-Swift (2.7.0)
- Flutter (1.0.0)
- package_info (0.0.1):
- Flutter
- url_launcher (0.0.1):
- Flutter
- url_launcher_macos (0.0.1):
- Flutter
- url_launcher_web (0.0.1):
- Flutter

DEPENDENCIES:
- couchbase_lite (from `.symlinks/plugins/couchbase_lite/ios`)
- Flutter (from `.symlinks/flutter/ios`)
- Flutter (from `Flutter`)
- package_info (from `.symlinks/plugins/package_info/ios`)
- url_launcher (from `.symlinks/plugins/url_launcher/ios`)
- url_launcher_macos (from `.symlinks/plugins/url_launcher_macos/ios`)
- url_launcher_web (from `.symlinks/plugins/url_launcher_web/ios`)

SPEC REPOS:
https://github.com/cocoapods/specs.git:
trunk:
- CouchbaseLite-Swift

EXTERNAL SOURCES:
couchbase_lite:
:path: ".symlinks/plugins/couchbase_lite/ios"
Flutter:
:path: ".symlinks/flutter/ios"
:path: Flutter
package_info:
:path: ".symlinks/plugins/package_info/ios"
url_launcher:
:path: ".symlinks/plugins/url_launcher/ios"
url_launcher_macos:
:path: ".symlinks/plugins/url_launcher_macos/ios"
url_launcher_web:
:path: ".symlinks/plugins/url_launcher_web/ios"

SPEC CHECKSUMS:
couchbase_lite: bb89ce19146f97fad810e568fd1a624ee6d9e4d9
CouchbaseLite-Swift: 89876f4656ef16945aea554127755ee40855af12
Flutter: 58dd7d1b27887414a370fcccb9e645c08ffd7a6a
couchbase_lite: 1e52b370772d124e99600ffacb9adbc30383d8b4
CouchbaseLite-Swift: fc942af766946a7b1efbee2cc9b72ae04ec632e1
Flutter: 0e3d915762c693b495b44d77113d4970485de6ec
package_info: 48b108e75b8802c2d5e126f208ef540561c98aef
url_launcher: a1c0cc845906122c4784c542523d8cacbded5626
url_launcher_macos: fd7894421cd39320dce5f292fc99ea9270b2a313
url_launcher_web: e5527357f037c87560776e36436bf2b0288b965c

PODFILE CHECKSUM: ebd43b443038e611b86ede96e613bd6033c49497
PODFILE CHECKSUM: 1b66dae606f75376c5f2135a8290850eeb09ae83

COCOAPODS: 1.7.5
COCOAPODS: 1.9.1
15 changes: 3 additions & 12 deletions example/ios/Runner.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -276,18 +276,9 @@
files = (
);
inputPaths = (
"${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-frameworks.sh",
"${PODS_ROOT}/CouchbaseLite-Swift/iOS/CouchbaseLiteSwift.framework",
"${PODS_ROOT}/CouchbaseLite-Swift/iOS/CouchbaseLiteSwift.framework.dSYM",
"${PODS_ROOT}/../.symlinks/flutter/ios/Flutter.framework",
"${BUILT_PRODUCTS_DIR}/couchbase_lite/couchbase_lite.framework",
);
name = "[CP] Embed Pods Frameworks";
outputPaths = (
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/CouchbaseLiteSwift.framework",
"${DWARF_DSYM_FOLDER_PATH}/CouchbaseLiteSwift.framework.dSYM",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/Flutter.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/couchbase_lite.framework",
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
Expand Down Expand Up @@ -368,7 +359,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
IPHONEOS_DEPLOYMENT_TARGET = 10.0;
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = iphoneos;
TARGETED_DEVICE_FAMILY = "1,2";
Expand Down Expand Up @@ -448,7 +439,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
IPHONEOS_DEPLOYMENT_TARGET = 10.0;
MTL_ENABLE_DEBUG_INFO = YES;
ONLY_ACTIVE_ARCH = YES;
SDKROOT = iphoneos;
Expand Down Expand Up @@ -496,7 +487,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
IPHONEOS_DEPLOYMENT_TARGET = 10.0;
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = iphoneos;
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
Expand Down
4 changes: 4 additions & 0 deletions example/ios/Runner/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,9 @@
</array>
<key>UIViewControllerBasedStatusBarAppearance</key>
<false/>
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key><true/>
</dict>
</dict>
</plist>
7 changes: 5 additions & 2 deletions example/lib/blocs/home_page_bloc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -135,15 +135,18 @@ class HomePageBloc {
// TODO
}

void logout() async {
await Repository.instance.logout(LogoutMethod.normal);
void logout() {
Repository.instance.triggerLogout(LogoutMethod.normal);
}

void dispose() {
_indexController.close();
_beerResponse?.close();
_sortSubject.close();
_stateSubject.close();

// This is called after all streams / listeners have been disposed
Repository.instance.logout();
}
}

Expand Down
7 changes: 5 additions & 2 deletions example/lib/data/repository.dart
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ class Repository {
Function(LoginResult) callback) async {
try {
var response = await ApiProvider.instance
.login(username, password, onLogout: logout);
.login(username, password, onLogout: triggerLogout);

if (response.statusCode == 200) {
var success = await _database.login(username, password);
Expand All @@ -113,10 +113,13 @@ class Repository {
}
}

Future<void> logout(LogoutMethod method) async {
void triggerLogout(LogoutMethod method) {
_isLoggedInSubject.add(false);
_lastLogoutMethodSubject.add(method);
}

// Call this once all streams / listeners have been cleaned up ( Your homepage )
Future<void> logout() async {
await _database.logout();
}

Expand Down
16 changes: 7 additions & 9 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,9 @@ class _ExampleAppState extends State<ExampleApp> {
}

// Create a query to fetch documents of type SDK.
var query = QueryBuilder.select([SelectResult.all().from("mydocs")])
.from("gettingStarted", as: "mydocs")
.where(Expression.property("type")
.from("mydocs")
.equalTo(Expression.string("SDK")));
var query = QueryBuilder.select([SelectResult.all()])
.from("gettingStarted")
.where(Expression.property("type").equalTo(Expression.string("SDK")));

// Run the query.
try {
Expand Down Expand Up @@ -137,10 +135,10 @@ class _ExampleAppState extends State<ExampleApp> {

@override
void dispose() async {
await replicator.removeChangeListener(_listenerToken);
await replicator.stop();
await replicator.dispose();
await database.close();
await replicator?.removeChangeListener(_listenerToken);
await replicator?.stop();
await replicator?.dispose();
await database?.close();

super.dispose();
}
Expand Down
4 changes: 1 addition & 3 deletions example/lib/pages/home_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -193,9 +193,7 @@ class _HomePageState extends State<HomePage> {
ListTile(
leading: Icon(Icons.person),
title: Text("Log Out"),
onTap: () async {
await _pageBloc.logout();
},
onTap: _pageBloc.logout,
),
],
))),
Expand Down
Loading

0 comments on commit 9bb4af7

Please sign in to comment.